0

Я пытаюсь установить два LinearLayouts в RelativeLayout (rootelement). Я вижу только одну строку. Не следует ли, чтобы ÄÄandroid: layout_below ** заставляли второй Linearlayout располагаться ниже первого LinearLayout?Wrap linearlayouts в relativelayout

Что не так? Это потому, что LinearLayout сама по себе является ViewGroup?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent"> 

<LinearLayout 
    android:id="@+id/addon1_row" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/weapon1_id" 
     android:layout_width="100dp" 
     android:layout_height="26dp" 
     android:src="@mipmap/weapon1" 
     android:adjustViewBounds="true" 
     /> 

    <ImageView 
     android:layout_width="100dp" 
     android:layout_height="26dp" 
     android:src="@mipmap/buy_button" 
     android:adjustViewBounds="true" 
     /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/addon2_row" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:layout_below="@+id/addon1_row"> 

    <ImageView 
     android:id="@+id/weapon2_id" 
     android:layout_width="100dp" 
     android:layout_height="26dp" 
     android:src="@mipmap/weapon2" 
     android:adjustViewBounds="true" 
     /> 

    <ImageView 
     android:layout_width="100dp" 
     android:layout_height="26dp" 
     android:src="@mipmap/buy_button" 
     android:adjustViewBounds="true" 

     /> 
</LinearLayout> 


</RelativeLayout> 
+1

Вы действительно не нужен RelativeLayout, учитывая текущее расположение. Но я бы оптимизировал все это (ради производительности), используя один RelativeLayout без LinearLayouts ИЛИ с помощью GridView (опять же, без дополнительных LinearLayouts). –

+1

@ Rotwang, спасибо, я буду считать, что – java

ответ

1

Это из-за вас установить высоту как линейной компоновки для "match_parent" просто установить его в "wrap_content"

<LinearLayout 
    android:id="@+id/addon1_row" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" <== Here 
    android:orientation="horizontal"> 


<LinearLayout 
    android:id="@+id/addon2_row" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" <== Here 
    android:layout_below="@+id/addon1_row" 
    android:orientation="horizontal">