Josh Beckwith
Josh Beckwith

Reputation: 1540

Android: how to 'insert' a layout into another layout?

I wasn't quite sure on how to ask this, but it would essentially be the equivalent of a custom directive in HTML, pseudo code below:

Main layout

<RelativeLayout>
    <TextView text="Our song list"/>
    <LinearLayout>
        <CustomLayoutHere>
    </LinearLayout>
</RelativeLayout>

Custom layout

<LinearLayout orientation="horizontal>
    <TextView text="Song name:"/>
    <ImageView background="albumart.png"/>
    <Button text="Add to favorites"/>
</LinearLayout>

So essentially this custom layout piece would be added into the LinearLayout above, once for each song.

Upvotes: 0

Views: 88

Answers (1)

Robin Dijkhof
Robin Dijkhof

Reputation: 19288

Use the include tag:

<RelativeLayout>
    <TextView text="Our song list"/>
    <LinearLayout>
        <include layout="@layout/custom_layout"/>
    </LinearLayout>
</RelativeLayout>

Upvotes: 1

Related Questions