我的GridView 6图像2列。我想在屏幕中间显示这6幅图像。我把重心属性中心,但该中心的元素只会水平。 GridView控件需要整个屏幕。
< GridView控件
机器人:ID =@ + ID / GridView控件
机器人:layout_above =@ ID /广告安卓:layout_alignParentTop =真
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:为numColumns =2
机器人:verticalSpacing =10dp
机器人:horizontalSpacing =10dp
机器人:stretchMode =columnWidth中
机器人:后台=#FFFFFF
机器人:重力=中心
/>
解决方案
下面是我做过什么让在GridView的项目中心(注意stretchmode,columnWidth中,重力和水平和垂直间距):
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=横向
机器人:填充=5dip>
< GridView控件
机器人:ID =@ + ID / GridView控件
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:columnWidth中=100dip
机器人:重力=中心
机器人:horizontalSpacing =10dip
机器人:为numColumns =3
机器人:stretchMode =spacingWidthUniform
机器人:verticalSpacing =10dip/>
< / LinearLayout中>
我花了一段时间来弄明白,但与这些不同的价值观,我能够让他们心搞乱。
I have GridView with 6 images in 2 columns. I want to display this 6 images in the middle of the screen. I set gravity properties to center but this center elements only horizontally. GridView takes whole screen.
<GridView
android:id="@+id/gridview"
android:layout_above="@id/ad" android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:background="#ffffff"
android:gravity="center"
/>
解决方案
Here is what I did to get the items in the gridview to center (notice the stretchmode, columnwidth, gravity and horizontal and vertical spacing):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="5dip" >
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="100dip"
android:gravity="center"
android:horizontalSpacing="10dip"
android:numColumns="3"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="10dip" />
</LinearLayout>
It took me a while to figure it out, but messing with those different values I was able to get them to center.