2016-12-18 3 views
0

Это мой XML-файл, который я создал. Я не могу установить высоту LinearLayout. Я установил ориентацию LinearLayout в горизонтальное положение, и я использовал layout_weight, чтобы установить высоту LinearLayout.Вложенная компоновка для Android-приложения не работает

Однако, когда я устанавливаю высоту TextView в match_parent, она не работает.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="16dp" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:paddingTop="16dp" 
    tools:context=".MainActivity" 
    android:weightSum="3"> 

    <LinearLayout 
     android:id="@+id/a" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal"> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="1"/> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="2"/> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/b" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:layout_below="@id/a"> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="3"/> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="4"/> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/c" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:layout_below="@id/b"> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="5"/> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="6"/> 
    </LinearLayout> 
</RelativeLayout> 
+1

Что означает «не работает» и «не работает»? – Chris

ответ

0

Это не работает, потому что RelativeLayout (корневой макет) не поддерживает веса. Поэтому измените свой верхний уровень RelativeLayout на LinearLayout с vertical orientation, и он должен работать.

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