How to create reusable viewgroups in XML?

388 views Asked by At

I often use the same LinearLayout with the same properties. For instance:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        ... other views & viewgroups here ....
</LinearLayout>

I would like to define an XML layout component, let's call it FullScreenVerticalLinearLayout, which i would use like this:

<FullScreenVerticalLinearLayout>
        ... other views & viewgroups here ....
</FullScreenVerticalLinearLayout>

<include> or <merge> tags seem to be perfect for view's reusability and aggregation, but not for viewgroup. Any clue on how to do this? Thanks.

1

There are 1 answers

1
Holoceo On BEST ANSWER

Via styles. http://developer.android.com/guide/topics/ui/themes.html For example add this to styles.xml:

<style name="LayoutStyle">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
</style>

And set this style:

<LinearLayout
    style="@style/LayoutStyle">
    ... other views & viewgroups here ....
</LinearLayout>