android merge set background not work
Recently,in a project, I try to set a merge labels's background property, the result is: background not showing up. After Checked out on the Internet, I find out what the merge label is.
Create a new HelloWorld android project, the layout file code is as follows:
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout> check out the layout:Everything was ok, the RelativeLayout's parent layout's id was "content". When we replace RelativeLayout to Merge, the result code below:
<merge 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </merge>check out the layout: You will find merge label disappeared, yes, it is this role, the whole layout which inside of the merge label was directly attached to its parent layout. So one layout is omitted, there will be performance boost! The google Phone APK use a lot of merge. Back to the title, you know why the Set Background invalid. When rendering layout, it does not exist. And that is not only the background, any such margin, padding attributes are also not work in merge label. http://www.easycpp.com/?p=20