将Gridview调整到整个屏幕

时间:2015-02-09 10:15:47

标签: android

我面临着将gridview调整到整个屏幕的问题。以下是我的代码:

具有gridview的activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.esoftall.esoft.MainActivity" >

    <RelativeLayout android:id="@+id/fullscreen_content_controls1"
            style="?metaButtonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay">

     <LinearLayout
            android:id="@+id/fullscreen_content_controls2"
            style="?metaButtonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="#508493"
            android:orientation="horizontal"
            android:layout_marginTop="50dp"
            android:layout_marginLeft="5dp"
            android:layout_marginStart="5dp"
            android:layout_marginRight="5dp"
            tools:ignore="UselessParent"
             >

     <TextView 
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/auto_complete"
        android:paddingLeft="10dip"
        android:paddingRight="10dip"
        android:paddingTop="10dip"
        android:textSize="17sp"
        android:textColor="#000000"/>    

     <AutoCompleteTextView
      android:id="@+id/autoCompleteTextView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:ems="10"
      android:layout_marginLeft="5dp"
      android:layout_marginStart="5dp"
      android:textColor="#000000" >
      <requestFocus />
    </AutoCompleteTextView>


   </LinearLayout>

   <LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/fullscreen_content_controls2"
    android:orientation="horizontal"
    >

    <GridView 
    android:id="@+id/grid_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="3dp"
    android:numColumns="auto_fit"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="5dp"
    android:padding="5dp"
    android:text="@+id/grd1"
    android:layout_gravity="center"
     />

    </LinearLayout>
    </RelativeLayout>

</FrameLayout>

name.xml代码,链接到imageadapter的网格视图:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/fullscreen_content_controls"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@color/white_overlay"
            android:orientation="horizontal"
            android:padding="20dip"
            android:radius="10dip"
            >

    <ImageView

        android:id="@+id/grid_image"
        android:layout_width="50sp"
        android:layout_height="50sp"
        android:contentDescription="@string/images"
        android:layout_centerInParent="true"

        />
    <LinearLayout
            android:id="@+id/fullscreen_content_controls3"
            style="?metaButtonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="#508493"
            android:orientation="horizontal"
            android:layout_marginTop="50dp"
            android:layout_marginLeft="5dp"
            android:layout_marginStart="5dp"
            android:layout_marginRight="5dp"
            >
   <RelativeLayout 
            android:id="@+id/fullscreen_content_controls1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@color/white_overlay"
            android:orientation="horizontal"
            >  
    <TextView 

    android:id="@+id/grid_item_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/img_text"
    android:layout_centerInParent="true"

        />
    </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

以下是gridview的图像显示:enter image description here

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试取出android:padding =&#34; 5dp&#34;

示例代码:

<GridView 
    android:id="@+id/grid_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="3dp"
    android:numColumns="auto_fit"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="5dp"
    android:text="@+id/grd1"
    android:layout_gravity="center"
     />