在相对布局中居中显示GridView

3

I have simple layout:

<?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居中在Relative布局中。我的间距总是固定的。结果是我有一个靠左对齐的GridView。如何将其居中在父元素中?

GridView


尝试使用 android-stretchMode - S.D.
1个回答

6
在布局中使用GridView时,android:numColumns="auto_fit"android:layout_width="wrap_content"冲突。这意味着:为了计算要形成多少列,需要宽度,但要找到宽度,我们需要多少列来环绕,形成循环依赖。
您可以使用android:stretchMode来让列填充空白空间。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接