您的位置:首页 > 移动开发 > Android开发

android merge 标签的使用

2015-05-30 14:58 537 查看
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ToggleButton" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:text="Golden Gate" />

</merge>


1.merge布局 和FrameLayout类似,相同的效果.不同的是 merge布局只能被<include>标签包含. 或者Activity.setContentView所使用.

当LayoutInflater遇到能被其他layout用<include>包含进去,并不再另外生成ViewGroup容器,本元 素也特别有用这个标签时,它会跳过它,并将<merge />内的元素添加到<merge />的父元素里. Activity能直接使用的原因是Activity的父元素是FrameLayout

2 merge 能被其他layout用<include>包含进去,并不再另外生成ViewGroup容器.就是说,会减少一层layout到达优化layout的目的

限制:

<merge />只能作为XML布局的根标签使用

· 当Inflate以<merge
/>开头的布局文件时,必须指定一个父ViewGroup,并且必须设定attachToRoot为true(参看inflate(int,
android.view.ViewGroup, Boolean)方法)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: