3

我的网格布局有一些问题。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:id="@+id/frag_books_grid_view_layout"
     android:orientation="vertical">
        <GridView
            android:padding="0dp"
            android:cacheColorHint="@color/bg_default"
            android:listSelector="@drawable/list_selector_background"
            android:id="@+id/frag_books_grid_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:stretchMode="spacingWidth"
            android:scrollbars="none"/>
</LinearLayout>

单品:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ListView
        android:cacheColorHint="@color/bg_default"
        android:scrollbars="none"
        android:listSelector="@drawable/list_selector_background"
        android:layout_gravity="center_vertical|left"
        android:gravity="center_vertical|left"
        android:paddingLeft="15dp"
        android:paddingRight="15dp" 
        android:id="@+id/frag_book_list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:verticalSpacing="5dp"/>
</LinearLayout>    

问题是单项没有左右填充。选择项目时看起来很糟糕:http: //i.imgur.com/rirNP.png

请帮忙解决。

4

2 回答 2

18

试试看

 <?xml version="1.0" encoding="utf-8"?>
    <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/menu_category"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:columnWidth="90dp"
        android:numColumns="auto_fit"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:gravity="center"
    />

信息

http://developer.android.com/guide/topics/ui/layout/gridview.html

于 2012-09-03T11:55:34.740 回答
5

这个最适合三列..

  <GridView
        android:id="@+id/gridview_Gallery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnWidth="65dp"
        android:gravity="center"
        android:horizontalSpacing="6dp"
        android:listSelector="#00000000"
        android:numColumns="3"
        android:scrollbars="none"
        android:stretchMode="columnWidth"
        android:verticalSpacing="-1dp" />
于 2012-09-03T11:59:55.527 回答