[英]GridLayout fill only one column leaving other columns empty
我有一個帶有3列的GridLayout
,內部有隨機數量的子項,我希望每個子項只能填充一列,並且只能填充一列,不能少也不能多。 但是下面的代碼使TextView
的填充更多。 我希望每個TextView
都能填充1/3的空間。
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:columnCount="3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
android:background="#abcdef"
app:viewAspectRatio="3"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
android:background="#fedcba"
app:viewAspectRatio="3" />
</android.support.v7.widget.GridLayout>
如果使用GridLayout
無法實現,我很想知道其他可能性
我不太確定,請嘗試以下操作:
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:columnCount="3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
android:background="#abcdef"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
android:background="#fedcba" />
</android.support.v7.widget.GridLayout>
要么 :
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:columnCount="3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
android:background="#abcdef"
app:viewAspectRatio="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_columnWeight="1"
android:background="#fedcba"
app:viewAspectRatio="1" />
</android.support.v7.widget.GridLayout>
希望對你有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.