我們正在編寫一個針對ICS +的應用程序,並且認爲GridLayout是最好的佈局範例,但似乎很少寫到它,而且我們遇到了一些對齊問題。Android中的水平居中視圖GridLayout
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_background"
android:rowCount="1"
android:columnCount="3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
android:background="@drawable/list_item_bg">
<ImageView
android:id="@+id/visibilityIcon"
android:layout_row="0"
android:layout_column="0"
android:src="@drawable/visibility_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<ImageView
android:id="@+id/windIcon"
android:layout_row="0"
android:layout_column="1"
android:src="@drawable/wind_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<ImageView
android:id="@+id/crosswindIcon"
android:layout_row="0"
android:layout_column="2"
android:src="@drawable/cloud_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
</GridLayout>
但是,左側的2個圖標保持左對齊,最右側的圖標以剩餘空間爲中心。
基本上我們需要做的是將每列的大小指定爲總屏幕大小的1/3(因爲3列)。我認爲這是GridLayout所做的,但看起來'wrap_content'導致了這種行爲(合理),但'match_parent'會導致第一列填滿整個屏幕,而不是填充它的單元格,這是我所期望的行爲。
我們似乎已經嘗試過重力,layout_gravity等的每種組合,但是我們從根本上做錯了什麼,或者發現了GridLayout的限制。
感謝您的幫助!
GridLayout似乎沒用! –