我花了好幾個小時的時間,看了沒有解決方案時找到的每個相關的SO問題。Android GridView不能正確縮放
這裏是我的問題:
我有圖像的GridView控件。我需要3列(以匹配iOS版本和美學)。如果將numColumns設置爲3,則每行圖像行的頂部和底部之間會有很多空間。如果我將寬度設置爲自動填充,我總是得到2,他們看起來更好,但更喜歡3列。
我錯過了什麼?
佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top" >
<LinearLayout
android:id="@+id/llayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
>
<ImageView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#666666"
android:clickable="false"
android:contentDescription="@string/title_card_collection"
android:src="@drawable/sportscard2x" />
</LinearLayout>
<GridView
android:id="@+id/cardGrid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_above="@+id/llayout"
android:gravity="center"
android:horizontalSpacing="2dip"
android:numColumns="3"
android:stretchMode="columnWidth"
android:layout_alignParentBottom="true"
android:verticalSpacing="2dip" >
</GridView>
我希望它是簡單的東西,我只是缺少。提前致謝。
更新:增加了截圖。問題是,只有1行顯示,如果向下滾動,您會看到其他3行,但中間有一個巨大的空間。
參考這個答案http://stackoverflow.com/questions/12363106/gridview-height-is-too-tall-when-using-an-imageview-inside/12363218#12363218 –
這並沒有幫助。已更新以顯示更多的XML – RiddlerDev
您可以發佈截圖或想要的結果樣機嗎?你現在有什麼。我剛剛使用了三列的gridView,沒有任何問題 – Jin35