GridView不居中;对齐的

时间:2014-05-02 15:34:44

标签: android android-layout android-gridview

我无法弄清楚这个左侧填充的来源。

我的网格不仅仅是未经中断,它似乎与右边对齐。怎么了?

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="8dp"
    android:paddingBottom="8dp">

    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridView"
        android:numColumns="auto_fit"
        android:columnWidth="240dp"
        android:stretchMode="spacingWidthUniform"
        android:verticalSpacing="22dp"
        android:horizontalSpacing="16dp"
        android:gravity="center_horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent = "true">
    </GridView>

</RelativeLayout>

2 个答案:

答案 0 :(得分:2)

我相信它来自

android:stretchMode="spacingWidthUniform"

删除并测试它。

答案 1 :(得分:1)

试试这个标签

 android:gravity="center" in GridView

作为

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridView"
        android:numColumns="3"// Changed to 3
        android:columnWidth="60dp"
        android:stretchMode="columnWidth"// Added
        android:verticalSpacing="22dp"
        android:horizontalSpacing="16dp"
        android:gravity="center_horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        >
    </GridView>

</RelativeLayout>