Reputation: 1437
I have a layout which consists of a hierarchy like this:
<ScrollView>
<LinearLayout <!-- vertical orientation --> >
<LinearLayout <!-- horizontal orientation --> >
<TextView/>
<TextView/>
</LinearLayout>
</LinearLayout>
</ScrollView>
My problem is that I have about 8-9 innermost Linear Layouts, all of them having the same design attributes. The only difference among them is id of Linear Layout and text of both the text views.
So, is there a way that every time I add a horizontal Linear Layout, only things I have to mention are the attributes not the same. That is, I do not want to write the same design attributes again and again.
Upvotes: 0
Views: 999
Reputation: 969
For this you can use tag , for reusing the same layout over and over again .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_bg"
android:gravity="center_horizontal">
<include layout="@layout/titlebar"
android:id="@+id/linear1/>
<include layout="@layout/titlebar"
android:id="@+id/linear2/>
...
Now you can access your different linear layout through their id and for the textView inside your common linear layout can also be accessed through the include id . say linear1.textView.setText="TDemo Text" . Set your text at run time . Hope this will solve your issue .for better idea , please go through this : https://developer.android.com/training/improving-layouts/reusing-layouts
Upvotes: 2