我正在使用支持v7 GridLayout
,但許多人指出,它不會正確測量其子寬度。GridLayout支持寬度問題
在這question,有一個解決方法,但解決方法是隨機爲我工作,對於它的一些值的工作,併爲一些孩子值它不。
所提出的解決方法:
android:layout_width="0dp"
app:layout_gravity="fill_horizontal"
我在運行時設置子值,所以我的猜測是僅由向測量孩子的寬度。
我正在使用支持v7 GridLayout
,但許多人指出,它不會正確測量其子寬度。GridLayout支持寬度問題
在這question,有一個解決方法,但解決方法是隨機爲我工作,對於它的一些值的工作,併爲一些孩子值它不。
所提出的解決方法:
android:layout_width="0dp"
app:layout_gravity="fill_horizontal"
我在運行時設置子值,所以我的猜測是僅由向測量孩子的寬度。
我解決了使用你所提到的解決方法,這裏提出:Android GridLayout not clipping text to column width這裏Daniel Lew's Coding Thoughts GridLayout Child View Clipping Issues作品:
android:layout_width="0dp"
app:layout_gravity="fill_horizontal"
在我的情況下,它以編程方式設置子值的時候,當我申請工作正常甚至最後一列中的所有孩子,如以下示例中所示:
<android.support.v7.widget.GridLayout
xmlns:grid="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/GridView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
grid:columnCount="2"
grid:rowCount="2"
grid:alignmentMode="alignBounds">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Label1"
android:id="@+id/textViewLabel1"
grid:layout_row="0"
grid:layout_column="0" />
<TextView
android:layout_width="0dp"
grid:layout_gravity='fill_horizontal'
android:layout_height="wrap_content"
android:text="Value1"
android:id="@+id/textViewValue1"
grid:layout_row="0"
grid:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Label2"
android:id="@+id/textViewLabel2"
grid:layout_row="1"
grid:layout_column="0" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
grid:layout_gravity='fill_horizontal'
android:text="Value2"
android:id="@+id/textViewValue2"
grid:layout_row="1"
grid:layout_column="1" />
</android.support.v7.widget.GridLayout>
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal"
你可以詳細說明爲什麼這段代碼解決了這個問題? –
使用本地GridLayout的同樣的問題! –
*有*一種在GridLayout裏面使用'TextView'的一致方法。看看我的答案在這裏:http://stackoverflow.com/a/23090059/1208581 – sulai