VendettaDroid
VendettaDroid

Reputation: 3111

include layout in another layout fills the view

I am working on a layout. temp1 is included in temp2. temp1 is working fine but when I include that in temp2. It fills the whole screen because the root in temp1 is set to fill_parent. What could be the solution in this case?

I want to display layout in temp1 in a small region of temp2 in the center.

temp1.xml

<RelativeLayout android:layout_height="fill_parent"
                 android:layout_width="fill_parent">


</RelativeLayout>

temp2.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:id="@+id/relativeLayout">
    <include
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            layout="@layout/temp1"/>
</RelativeLayout>

</RelativeLayout>

Upvotes: 1

Views: 645

Answers (1)

Steven Byle
Steven Byle

Reputation: 13269

You can override the layout_* fields of the root view of the layout you are including, in this case they override the root RelativeLayout in @layout/temp1.

You can use margin, and adjust it to the amount of border you want (100dp is just an example):

<include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="100dp"
        layout="@layout/temp1"/>

Or you can set the size you want (100dp is just an example):

<include
        android:layout_width="100dp"
        android:layout_height="100dp"
        layout="@layout/temp1"/>

Or you can just show the content that is there (temp1 has nothing in it as of now):

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

See http://developer.android.com/training/improving-layouts/reusing-layouts.html for more info.

Upvotes: 1

Related Questions