3

私は単純なレイアウトを持っています:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<GridView
    android:id="@+id/photo_browser_grid_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:gravity="center"
    android:horizontalSpacing="5dp"
    android:verticalSpacing="5dp"
    android:stretchMode="none"
    android:numColumns="auto_fit" 
    android:columnWidth="100dp">
</GridView>

GridView を相対レイアウト内の中央に配置したいと考えています。私の間隔は常に固定されています。その結果、GridView が左に配置されました。親の内側に配置するにはどうすればよいですか?

グリッドビュー

4

1 に答える 1

6

レイアウトの GridView の場合、 とandroid:numColumns="auto_fit"競合しandroid:layout_width="wrap_content"ます。つまり、形成する列の数を計算するには幅が必要ですが、幅を見つけるには、循環する列の数が必要です。

を使用android:stretchModeして、列が空のスペースを埋めることができます。

于 2012-12-01T14:39:47.523 に答える