作者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
→ sennin32:目前還是程式計算...有沒有高手知道如何用xml處理呢!? 04/28 00:07
推 f8181810:程式計算+1,我都重設layout要不然畫面會很難看= = 04/29 16:24