作者sennin32 (sennin32)
看板AndroidDev
标题[问题] 关於gridview
时间Sat Apr 27 15:00:11 2013
想问一下关於gridview的一些问题
主要是layout没有照我所希望的样子layout出来
我只是很简单的希望grid有两栏,而每个grid都是正方形,每个grid间有我指定的space
让我在这个grid中放进我的正方形图片
但是却一直有些小问题:
xml中的gridview如下
<GridView
android:id="@+id/gridview_coupon"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/bar_header"
android:layout_above="@+id/bottom_bar"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:horizontalSpacing="5dp"
android:verticalSpacing="10dp"
android:numColumns="2"
android:animateLayoutChanges="true"
android:background="@drawable/bg_main">
</GridView>
然後每个grid的元素xml如下
<RelativeLayout xmlns:android="
http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/darkgray" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/imagedesc" />
<ImageView
android:id="@+id/mask_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_cp_mask_remove"
android:visibility="gone"
android:contentDescription="@string/imagedesc" />
</RelativeLayout>
我试着去改过宽度或高度改为match parent、fill parent
但是都会有错误,错误是这样的:
感觉每个grid的高度都被固定住
如果手机解析度比较小,宽度不够宽使的图缩小,此时高度应该也要跟着缩小
但会变成上下有不该出现的空隙(每个grid的高度太高而没有贴合)
而如果手机解析度较高,因为宽度较宽所以图片会被放大
但却变成会被高度限制住,使的两侧出现不该出现的空隙(grid高度太小限制图片放大)
请问这样的情况该如何处理呢?
谢谢各位QQ
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.34.190.138
1F:→ sennin32:目前还是程式计算...有没有高手知道如何用xml处理呢!? 04/28 00:07
2F:推 f8181810:程式计算+1,我都重设layout要不然画面会很难看= = 04/29 16:24