我有 GridView:
<?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:cacheColorHint="@color/bg_default"
android:listSelector="@drawable/list_selector_background"
android:id="@+id/frag_books_grid_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="120px"
android:gravity="center"
android:horizontalSpacing="15dp"
android:scrollbars="none"
android:stretchMode="columnWidth"
/>
</LinearLayout>
和单个项目(放置在此网格的单元格中):
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
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:padding="15dp"
android:id="@+id/frag_book_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="5dp"/>
它的外观: http: //i.imgur.com/rhZiu.png 蓝色选择一切正常,但单元格的内容不在其中居中。这张图片解释了我想要的:http: //i.imgur.com/OumWu.png