Ungureanu Liviu
Ungureanu Liviu

Reputation: 4124

Add Multiple LinearLayout inside of another LinearLayout is not working as expected

I have a LinearLayout which should contains a list of items (each item is a LinearLayout). The problem is that the childs items (LinearLayouts) are not displayed one below another: just the fist one is visible.

This is my layout.xml:

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/label_TextView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_weight="2"
    android:paddingLeft="@dimen/form_label_padding_left"
    android:text="" />

<LinearLayout
    android:id="@+id/form_list_holder"
    android:layout_width="0dp"
    android:layout_height="wrap_content"        
    android:layout_weight="8"
    android:orientation="horizontal"
    android:background="@color/form_list_background" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/label_TextView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"
            android:paddingLeft="@dimen/form_label_padding_left"
            android:text="1" />

        <EditText
            android:id="@+id/edtx_input1"
            android:layout_width="0dp"
            android:layout_height="@dimen/form_input_height"
            android:layout_marginTop="@dimen/form_edittext_margin_top"
            android:layout_weight="5" />

        <EditText
            android:id="@+id/edtx_remark1"
            android:layout_width="0dp"
            android:layout_height="@dimen/form_input_height"
            android:layout_marginTop="@dimen/form_edittext_margin_top"
            android:layout_weight="3"
            android:hint="@string/remarks"
            android:visibility="invisible" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/label_TextView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"
            android:paddingLeft="@dimen/form_label_padding_left"
            android:text="1" />

        <EditText
            android:id="@+id/edtx_input2"
            android:layout_width="0dp"
            android:layout_height="@dimen/form_input_height"
            android:layout_marginTop="@dimen/form_edittext_margin_top"
            android:layout_weight="5" />

        <EditText
            android:id="@+id/edtx_remark2"
            android:layout_width="0dp"
            android:layout_height="@dimen/form_input_height"
            android:layout_marginTop="@dimen/form_edittext_margin_top"
            android:layout_weight="3"
            android:hint="@string/remarks"
            android:visibility="invisible" />
    </LinearLayout>
</LinearLayout>

Do you know why this is happen? I thought that in a LinearLayout if there is not more available space on current line, the childs will be displayed on the next line.

Upvotes: 2

Views: 16305

Answers (4)

deepa
deepa

Reputation: 2494

Try with Linear layout within RelativeLayout. so that you can set the

android:layout_below="@+id/above_layout" //above_layout is the id of previous layout


<RelativeLayout>
    <LinearLayout
      android:id="@+id/layout1"
      android:layout_width="Wrap_Content"
      android:layout_height="Wrap_Content">

    </LinearLayout>
    <LinearLayout
      android:id="@+id/layout2"
      android:layout_width="Wrap_Content"
      android:layout_height="Wrap_Content"
      android:layout_below="@+id/layout1">

    </LinearLayout>
      <LinearLayout
      android:id="@+id/layout3"
      android:layout_width="Wrap_Content"
      android:layout_height="Wrap_Content"
      android:layout_below="@+id/layout2">

    </LinearLayout>
</RelativeLayout>

It may helpful to you..

Upvotes: 1

AITAALI_ABDERRAHMANE
AITAALI_ABDERRAHMANE

Reputation: 2519

try this

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/form_list_holder"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"        
    android:layout_weight="8"
    android:orientation="vertical"
    android:background="@color/form_list_background" >

    <TextView
          android:id="@+id/label_TextView"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical"
          android:layout_weight="2"
          android:paddingLeft="@dimen/form_label_padding_left"
          android:text="" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/label_TextView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"
            android:paddingLeft="@dimen/form_label_padding_left"
            android:text="1" />

        <EditText
            android:id="@+id/edtx_input1"
            android:layout_width="0dp"
            android:layout_height="@dimen/form_input_height"
            android:layout_marginTop="@dimen/form_edittext_margin_top"
            android:layout_weight="5" />

        <EditText
            android:id="@+id/edtx_remark1"
            android:layout_width="0dp"
            android:layout_height="@dimen/form_input_height"
            android:layout_marginTop="@dimen/form_edittext_margin_top"
            android:layout_weight="3"
            android:hint="@string/remarks"
            android:visibility="invisible" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/label_TextView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"
            android:paddingLeft="@dimen/form_label_padding_left"
            android:text="1" />

        <EditText
            android:id="@+id/edtx_input2"
            android:layout_width="0dp"
            android:layout_height="@dimen/form_input_height"
            android:layout_marginTop="@dimen/form_edittext_margin_top"
            android:layout_weight="5" />

        <EditText
            android:id="@+id/edtx_remark2"
            android:layout_width="0dp"
            android:layout_height="@dimen/form_input_height"
            android:layout_marginTop="@dimen/form_edittext_margin_top"
            android:layout_weight="3"
            android:hint="@string/remarks"
            android:visibility="invisible" />
    </LinearLayout>
</LinearLayout>

Upvotes: 0

Lazy Ninja
Lazy Ninja

Reputation: 22527

You have set all your android:layout_width="0dp", meaning you wont be able to see anything. Change 0dp to match_parent.

Upvotes: 0

Sherif elKhatib
Sherif elKhatib

Reputation: 45942

Your LinearLayout whose id is form_list_holder has a android:orientation="horizontal".

The orientation should be Vertical instead usign android:orientation="vertical"

Upvotes: 4

Related Questions