Ahmed Abd Elmoniem Ahmed Abd Elmoniem - 1 month ago 10
Android Question

Two levels of layout include - Android

I have 3 layouts : 'a', 'b', 'c'.

'a' is included on 'b', and 'b' is included on 'c'. but when c rendered it shows me the content of 'b' only without 'a'.

is that because I can't have multilevel includes?

the layouts code:

a :-

<?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="match_parent"
android:orientation="vertical">

<LinearLayout
android:id="@+id/AdInfoDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/searchLayout"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:layoutDirection="rtl"
android:orientation="horizontal">


<EditText
android:id="@+id/AdNo"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:hint="العدد"
android:inputType="number" />

<RadioGroup
android:id="@+id/AdStatusGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:orientation="horizontal"
android:weightSum="4">

<RadioButton
android:id="@+id/AdStatus1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/excellent" />

<RadioButton
android:id="@+id/AdStatus2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/good" />

<RadioButton
android:id="@+id/AdStatus3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/bad" />


</RadioGroup>


</LinearLayout>

<LinearLayout
android:id="@+id/BadAdInfoDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/searchLayout"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:layoutDirection="rtl"
android:gravity="left"
android:orientation="horizontal"
android:weightSum="2">


<RadioGroup
android:id="@+id/BadAdStatusGroup"
android:layout_width="294dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:orientation="horizontal"
android:weightSum="4">

<RadioButton
android:id="@+id/BadAdStatus1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/excellent" />

<RadioButton
android:id="@+id/BadAdStatus2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/good" />

<RadioButton
android:id="@+id/BadAdStatus3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/bad" />


</RadioGroup>


</LinearLayout>


</LinearLayout>


b :-

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

<LinearLayout
android:id="@+id/zainInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchLayout"
android:layout_weight="3"
android:background="#D8BFD8"
android:orientation="vertical"
android:layoutDirection="rtl"
android:visibility="visible">

<LinearLayout
android:id="@+id/zainInfoDetails1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchLayout"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:layout_weight="3"
android:layoutDirection="rtl"
android:orientation="horizontal">




<CheckBox
android:id="@+id/zainStickCB"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="fill"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:text="@string/stickers"
android:textDirection="rtl"
android:textSize="20dp" />


<include layout="@layout/ad_type" android:id="a"/>


</LinearLayout>

<LinearLayout
android:id="@+id/zainInfoDetails2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchLayout"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:layout_weight="3"
android:orientation="horizontal">

<CheckBox
android:id="@+id/zainDangCB"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="fill"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:text="@string/danglers"
android:textDirection="rtl"
android:textSize="20dp" />


<include layout="@layout/ad_type" android:id="a"/>



</LinearLayout>


<LinearLayout
android:id="@+id/zainInfoDetails3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchLayout"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:layout_weight="3"
android:orientation="horizontal">

<CheckBox
android:id="@+id/zainWashCB"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="fill"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:text="@string/wash_lines"
android:textDirection="rtl"
android:textSize="20dp" />

<include layout="@layout/ad_type" android:id="a" />

</LinearLayout>


</LinearLayout>

</LinearLayout>


c :-

<LinearLayout
android:id="@+id/mtnInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchLayout"
android:layout_weight="3"
android:background="#FFFFE0"
android:orientation="vertical"
android:visibility="visible">




<include layout="@layout/b"


</LinearLayout>

Answer

In your layout b change the filling to wrap_content

android:layout_height="match_parent"

to

android:layout_height="wrap_content"

This goes for every kind of layout you wish to include. As soon as you set it to match_parent other layouts will have no space.