Sal-laS
Sal-laS

Reputation: 11649

Call an android layout in another one to make a nested layout

Sorry I am new in Android

Because of my large contents I am going to create a ScrollView. In this way, I have created some parts of my content in 1 file (let's call it FirstLayout.xml) and the other part SeconedLayout.xml. Now I am going to call both of them in a single XML file.(Parent.xml)

But the problem is, I don't know, how should I call them in my ScrollView?

here is the code

FirstLayout.xml

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
.
.
.
</AbsoluteLayout>

SeconedLayout.xml is:

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
  ...
    </LinearLayout>

Parent.xml

visible

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

<!-- Call FirstLayout  -->  


<!-- Call SecondLayout  -->
</ScrollView>

Upvotes: 2

Views: 1457

Answers (4)

Vivek Kumar Srivastava
Vivek Kumar Srivastava

Reputation: 2158

you can include layout like

<include layout="@layout/FirstLayout" />

<include layout="@layout/SeconedLayout" />

so your layout should be like

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scroller"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" >
     <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    <include layout="@layout/FirstLayout" />

    <include layout="@layout/SeconedLayout" />
  </LinearLayout>
    </ScrollView>

Upvotes: 1

mohamed khalloufi
mohamed khalloufi

Reputation: 467

try just to use the include tag like that :

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >
<include layout="@layout/FirstLayout" />
<include layout="@layout/SeconedLayout" />
</ScrollView>

But for better performance, use the tag, that helps eliminate redundant view groups in your view hierarchy when including one layout within another. Get a look here.

Upvotes: 0

MohsinSyd
MohsinSyd

Reputation: 175

Use include tag, e.g

<include layout="@layout/firstlayout" />

Upvotes: 0

Sandeep
Sandeep

Reputation: 1814

You should use include tag:

<include 
    layout="@layout/SeconedLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

Upvotes: 2

Related Questions