2014-10-03 91 views
1

正在使用android中的gridview开发自定义图库。现在面临的列发布计数..my gridview的XML是,在android中使用gridview自动调整gridview中的单元格大小android

<GridView 
    android:id="@+id/gv_gallery" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:numColumns="auto_fit" 
    android:choiceMode="multipleChoice" 
    android:stretchMode="columnWidth" 
    android:gravity="center" 
    android:columnWidth="179dp"> 
</GridView> 

我的网格项目布局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="179dp" 
    android:layout_height="131dp" 
    android:padding="1dp" > 

    <ImageView 
     android:id="@+id/iv_thumbnail" 
     android:contentDescription="@string/iv_content_description" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="centerCrop" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/tv_folder" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:layout_alignParentBottom="true" 
     android:text="@string/tv_folder" 
     android:padding="12dp" 
     android:textColor="@color/white" 
     android:background="@color/transparent_black"/> 

</RelativeLayout> 

当然它根据设备宽度方的动态维护列,但有不同的列间距在不同的设备.. 我怎么能克服这个问题。?

enter image description here

enter image description here

+0

您可以上传图片吗? – AndroidEnthusiast 2014-10-03 10:20:06

+0

@AndroidEnthusiast plese检查上传的图片 – sam 2014-10-03 10:31:26

+0

行为是有点期待。你明确地将高度和宽度设置为像素值。当(列数×宽度)不能再容纳更多图像时,它将它们拉伸到“自动适应”并移动到新行。尽管可以使用Horizo​​ntalSpacing来控制图像之间的间距为固定大小,但是在右侧会有额外的空白区域。看到这里http://developer.android.com/reference/android/widget/GridView.html – kha 2014-10-03 10:47:22

回答

0

要均匀地分布的大小不使用固定的大小对每个网格项。

将宽度设置为wrap_content,您也可以指定列数