0

私は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

4

1 に答える 1

0

ネストされたスクロール可能なコンポーネントを持つことはお勧めできませんが、リスト ビューのサイズが に設定されていmatch_parentます。使用可能なすべてのスペースをすでに占有しているため、中央に配置することはできません。

中央に配置する場合は、最初に listView を小さくします (固定サイズを設定します)。次に、コンテナでgravity="center"を使用します。コンテナに均一なパディングを適用することもできます。これにより、listView が中央に表示されます。

于 2012-09-03T13:16:18.623 に答える