使得在Android上的GridView中心中心、Android、GridView

由网友(该梦归何处)分享简介:< XML版本=1.0编码=UTF-8&GT?;< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PAR...

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=横向
    机器人:后台=#FFFFFF
    机器人:layout_gravity =center_horizo​​ntal
    机器人:填充=5dip>
    < GridView控件
        机器人:ID =@ + ID / homeGridView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:columnWidth中=160dip
        机器人:adjustViewBounds =真
        机器人:layout_gravity =center_horizo​​ntal
        机器人:layout_centerInParent =真
        机器人:重力=center_horizo​​ntal
        机器人:为numColumns =2
        机器人:stretchMode =无/>
< / RelativeLayout的>
 

我已经突破就如何使GridView的中心,卧式和立式我的头。我还附上我的屏幕截图为同一个。 下面是我的形象code。

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=横向
    机器人:layout_gravity =center_horizo​​ntal
    机器人:填充=5dip>

    < ImageView的
        机器人:ID =@ + ID / grid_item_image
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =center_horizo​​ntal
        机器人:layout_centerHorizo​​ntal =真正的>
    < / ImageView的>

< / RelativeLayout的>
 

解决方案

那么,如果你不想使用TableLayout(as您在precedent帖子说),处理GridView控件是pretty的复杂(我已经失去了很多的时间在这个)。 唯一的想法,我有他强迫你的GridView有一个确切的宽度,即是​​你2次的总和。160dip * 2

 机器人:layout_width =320dip
 
android中gridview里怎么添加button按钮啊

随意添加10dip以上的填充。

注:我不知道这是否是最好的方式,如果这是正确的每个设备。试试吧,让我知道。)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:background="#FFFFFF"
    android:layout_gravity="center_horizontal"
    android:padding="5dip" >
    <GridView
        android:id="@+id/homeGridView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:columnWidth="160dip"
        android:adjustViewBounds="true" 
        android:layout_gravity="center_horizontal"
        android:layout_centerInParent="true"
        android:gravity="center_horizontal"
        android:numColumns="2"
        android:stretchMode="none"/>
</RelativeLayout>

I have been breaking my head on how to make the gridView center horizonal and vertical. I have also attached my screen-shot for the same. Below is my image code.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:layout_gravity="center_horizontal"
    android:padding="5dip" >

    <ImageView
        android:id="@+id/grid_item_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"  
        android:layout_centerHorizontal="true">
    </ImageView>

</RelativeLayout>

解决方案

Well if you don't want to use TableLayout (as you says in your precedent post), dealing with GridView is pretty complicated (i've lost a lot of times on this). The only idea i have his to force your GridView to have an exact width, that is the sum of your 2 views: 160dip * 2.

    android:layout_width="320dip"

Feel free to add 10dip or more for padding.

N.B.: i'm not sure if this is the best way and if this is proper for every device. Try it and let me know ;) .

阅读全文

相关推荐

最新文章