<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</merge>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal"
tools:context=".MainActivity" >
<include layout="@layout/layout1" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<merge/>标签帮助你排除把一个布局插入到另一个布局时产生的多余的View Group.如,你的被复用布局是一个垂直的线性布局,包含两个子视图,当它作为一个被复用的元素被插入到另一个垂直的线性布局时,结果就是一个垂直的LinearLayout里包含一个垂直的LinearLayout。这个嵌套的布局并没有实际意义,而且会让UI性能变差。为了避免插入类似冗余的View Group,你可以使用<merge/>标签标签作为可复用布局的根节点
我们来创建一个 drawable 的XML 文件。
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#80FF00FF"
android:startColor="#FFFF0000" />
<padding
android:bottom="7dp"
android:left="50dp"
android:right="7dp"
android:top="20dp" />
<corners android:radius="8dp" />
</shape>
android:angle 表示从哪个角度开始,
android:shape="rectangle"设置图形, 默认的也是长方形;
corners 表示是有半径;
android:startColor="#FFFF0000" 设置背景的起始颜色,
android:endColor="#80FF00FF"设置背景的最终色,背景在这两种颜色之间渐变。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/transparent"
android:state_window_focused="false"/>
<item android:drawable="@drawable/selector_background_disabled"
android:state_enabled="false"
android:state_focused="true"
android:state_pressed="true"/>
<item android:drawable="@drawable/lselector_background_disabled"
android:state_enabled="false"
android:state_focused="true"/>
</selector>