Issue
I have two layouts (~80 lines) which differ from each other only in several text values. Can I remove such a duplication via xml? Or I can do it only programmatically by setting different string resources each time?
Simple example:
first xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background"
android:orientation="vertical"
android:paddingTop="@dimen/padding_top"
android:paddingBottom="@dimen/padding_bottom"
android:paddingLeft="@dimen/padding_left"
android:paddingRight="@dimen/padding_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/image"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<View
android:layout_height="@dimen/space_between_image_and_text"
android:layout_width="1dp" />
<TextView
android:text="@string/title_1"
android:textStyle="bold"
android:textColor="@color/text_color_title"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="@string/details_1"
android:textColor="@color/text_color_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
second xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background"
android:orientation="vertical"
android:paddingTop="@dimen/padding_top"
android:paddingBottom="@dimen/padding_bottom"
android:paddingLeft="@dimen/padding_left"
android:paddingRight="@dimen/padding_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/image"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<View
android:layout_height="@dimen/space_between_image_and_text"
android:layout_width="1dp" />
<TextView
android:text="@string/title_2"
android:textStyle="bold"
android:textColor="@color/text_color_title"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="@string/details_2"
android:textColor="@color/text_color_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
They differ only by text values: @string/title_1
vs @string/title_2
, and, @string/details_1
vs @string/details_2
.
Sorry for my English
Solution
just use the same layout - give the textviews id's and set the strings after inflation
Answered By - ligi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.