简体   繁体   中英

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.

Use the include tag:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM