Reference: http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources
Refer to the last exercise of Alternative Resources. Both /res/layout-land/activity_main.xml and /res/layout-large/activity_main.xml have the same layout. We can create alias resources refer to a common xml file.
Create: /res/values-land/refs.xml and /res/values-large/refs.xml.
Both define resource of type="layout" with name="activity_item_list", refer to the same layout file /res/layout/activity_main_horizontal.xml
<resources>
<item type="layout" name="activity_main">@layout/activity_main_horizontal</item>
</resources>
Create the common layout /res/layout/activity_main_horizontal.xml. Actually it's the original /res/layout-land/activity_main.xml and /res/layout-large/activity_main.xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:src="@drawable/ic_launcher"
tools:context=".MainActivity" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/myqualifier"
tools:context=".MainActivity" />
</LinearLayout>
</RelativeLayout>
Delete the original duplicated layout, /res/layout-land/activity_main.xml and /res/layout-large/activity_main.xml.
It have the same result of the last exercise, Providing Alternative Resources.
Title: Creating alias resources
Rating: 100% based on 99998 ratings. 10 user reviews.
Post by 11:07 AM
Rating: 100% based on 99998 ratings. 10 user reviews.
Post by 11:07 AM
0 comments:
Post a Comment