2017-02-22 8 views
0

У меня есть GridLayout с 3 колонками и случайным количеством детей внутри, я хочу, чтобы каждый ребенок заполнял одну и только одну колонку, не меньше и не более. Но нижеследующий код делает заполнение более TextView. Я хочу, чтобы каждый TextView заполнил 1/3 пространства.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="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, я хотел бы знать о других возможностях

ответ

0

Я не совсем уверен, но попробуйте это:

<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> 

Надеюсь, это поможет

+0

'viewAspectRatio' не является свойством' TextView' или 'GridLayout'. Его пользовательский attr, который я просто забыл удалить – Sourabh

+0

android: layout_columnSpan = "1" Попытайтесь добавить это в свои TextViews :) Например, это займет всего один столбец вашего gridview – Kurapika

Смежные вопросы