行中心gridview列

时间:2012-08-12 00:13:43

标签: android gridview center children

我有一个gridview,有一定数量的列(比方说,5)。但是,如果我在图像适配器中设置了6个图像,则第6个图像会自动转到新行,并被分配到第一列。我正在寻找的行为是自动(或以编程方式,以某种方式)将额外的子元素集中在新行中......例如:

A B C D E
    F

以下是我对gridview的XML:

<GridView android:id="@+id/gridview" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:columnWidth="10dip"
android:numColumns="10" android:horizontalSpacing="10dip"
android:stretchMode="columnWidth"
xmlns:android="http://schemas.android.com/apk/res/android"
android:verticalSpacing="3dp"
android:layout_below="@+id/TopLayout"
android:layout_gravity="center"></GridView>

1 个答案:

答案 0 :(得分:0)

您无法更改给定行的cols数。我能想到的唯一技巧是使用奇数列并在适配器所基于的列表中插入void条目。例如。如果您有5个cols和6个图像,请在位置5和6处插入2个void条目,以便最后一个图像居中。