EagerToLearn
EagerToLearn

Reputation: 675

Linearlayout missing in inside other LinearLayout

I have two LinearLayout like below structure.

<LinearLayout
    android:orientation="vertical">

        <LinearLayout
        android:id="@+id/kanji"
        android:layout_width="match_parent"
        android:layout_height="120dp"/>

        <LinearLayout
        android:id="@+id/goi"
        android:layout_width="match_parent"
        android:layout_height="120dp">

</LinearLayout>

The problem is the second LinearLayout (id=goi) is not showing as expected. I tried changing the top layout to RelativeLayout but it didn't work also.

Why is this occuring?

My actual code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:background="@drawable/rounded_corner_2"
    android:layout_margin="10dp"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/kanji"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:orientation="horizontal"
        android:background="@drawable/rounded_corner_2"
        android:layout_margin="0dp">

        <TextView
            android:layout_width="80dp"
            android:layout_height="match_parent"
            android:text="漢"
            android:textColor="@color/green"
            android:gravity="center"
            android:textSize="70sp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@drawable/rounded_corner_2"
            android:layout_margin="10dp"
            android:padding="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:text="漢字"
                android:textColor="@color/green"
                android:textSize="20sp"
                android:gravity="left"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="15dp"
                android:text="漢字"
                android:textColor="@android:color/darker_gray"
                android:textSize="10sp"
                android:gravity="left"/>

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

                <ProgressBar
                    android:layout_width="160dp"
                    android:layout_height="match_parent"
                    style="?android:attr/progressBarStyleHorizontal"
                    android:outlineSpotShadowColor="@color/green"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="end"
                    android:text="100/140"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/goi"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:orientation="horizontal"
        android:background="@drawable/rounded_corner_2"
        android:layout_margin="0dp">

        <TextView
            android:layout_width="80dp"
            android:layout_height="match_parent"
            android:text="漢"
            android:textColor="@color/green"
            android:gravity="center"
            android:textSize="70sp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@drawable/rounded_corner_2"
            android:layout_margin="10dp"
            android:padding="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:text="漢字"
                android:textColor="@color/green"
                android:textSize="20sp"
                android:gravity="left"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="15dp"
                android:text="漢字"
                android:textColor="@android:color/darker_gray"
                android:textSize="10sp"
                android:gravity="left"/>

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

                <ProgressBar
                    android:layout_width="160dp"
                    android:layout_height="match_parent"
                    style="?android:attr/progressBarStyleHorizontal"
                    android:outlineSpotShadowColor="@color/green"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="end"
                    android:text="100/140"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

Upvotes: 2

Views: 645

Answers (5)

Ilya Mashin
Ilya Mashin

Reputation: 954

You can use the directive <include></include> but I would advise doing an implementation on constraint layout

Upvotes: 1

chetna
chetna

Reputation: 94

The height of your parent LinearLayuot and child LinearLayouts is 120dp. You will need to change the height of child layouts to fit into the parent layout

Upvotes: 2

R7G
R7G

Reputation: 1060

It is happening because your top layout has fixed height

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:background="@drawable/rounded_corner_2"
    android:layout_margin="10dp"
    android:orientation="vertical">

update this into

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded_corner_2"
    android:layout_margin="10dp"
    android:orientation="vertical">

Upvotes: 3

AskNilesh
AskNilesh

Reputation: 69681

Linearlayout missing in inside other LinearLayout

Your root LinearLayout hight is 120dp and you have 2 child LinearLayout with same hight of 120dp so there is no space for second LinearLayout to visible

Solution

Change your root LinearLayout hight to android:layout_height="wrap_content" it will work

Try this

<LinearLayout
    android:id="@+id/kanji"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:orientation="horizontal"
    android:background="@drawable/rounded_corner_2"
    android:layout_margin="0dp">

    <TextView
        android:layout_width="80dp"
        android:layout_height="match_parent"
        android:text="漢"
        android:textColor="@color/green"
        android:gravity="center"
        android:textSize="70sp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@drawable/rounded_corner_2"
        android:layout_margin="10dp"
        android:padding="10dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:text="漢字"
            android:textColor="@color/green"
            android:textSize="20sp"
            android:gravity="left"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="15dp"
            android:text="漢字"
            android:textColor="@android:color/darker_gray"
            android:textSize="10sp"
            android:gravity="left"/>

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

            <ProgressBar
                android:layout_width="160dp"
                android:layout_height="match_parent"
                style="?android:attr/progressBarStyleHorizontal"
                android:outlineSpotShadowColor="@color/green"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="end"
                android:text="100/140"
                android:textColor="@android:color/darker_gray"/>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

<LinearLayout
    android:id="@+id/goi"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:orientation="horizontal"
    android:background="@drawable/rounded_corner_2"
    android:layout_margin="0dp">

    <TextView
        android:layout_width="80dp"
        android:layout_height="match_parent"
        android:text="漢"
        android:textColor="@color/green"
        android:gravity="center"
        android:textSize="70sp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@drawable/rounded_corner_2"
        android:layout_margin="10dp"
        android:padding="10dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:text="漢字"
            android:textColor="@color/green"
            android:textSize="20sp"
            android:gravity="left"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="15dp"
            android:text="漢字"
            android:textColor="@android:color/darker_gray"
            android:textSize="10sp"
            android:gravity="left"/>

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

            <ProgressBar
                android:layout_width="160dp"
                android:layout_height="match_parent"
                style="?android:attr/progressBarStyleHorizontal"
                android:outlineSpotShadowColor="@color/green"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="end"
                android:text="100/140"
                android:textColor="@android:color/darker_gray"/>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

Upvotes: 3

Berke Atac
Berke Atac

Reputation: 156

The parent LinearLayout has a height of 120px as does the first child of it. So the first child LinearLayout fills up all the height of the parent layout.

You can either increase the height of parent LinearLayout or make it "wrap_content" so it dynamically adjusts its height to the content it has.

Upvotes: 3

Related Questions