簡體   English   中英

GridLayout僅填充一列,而其他列為空

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM