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

Android中文API- <merge/> 标签

2016-04-25 17:55 447 查看
Use <merge/> tag这<merge/>标签,帮助我们在include一个布局的时候,消除多余的View Groups,例如,你的主布局文件是一个竖直的linearlayout。<Linearyoutxmlns:android=http://schemas.android.com/apk/res/androidAndroid:layout_width=”match_parent”Android:layout_height=”match_parent”Android:orientation = ”vertical”>    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="text"/>    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="text"/>    <include Layout=”@layout/ok_no_pannel”/></ Linearyout>此时:分析以下ok_no_pannel.xml,文件的写法:<Linearyoutxmlns:android=http://schemas.android.com/apk/res/androidAndroid:layout_width=”match_parent”Android:layout_height=”match_parent”Android:orientation = ”vertical”>
   <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/add"/>    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/delete"/></ Linearyout >以上的文件的写法,你会发现一旦include执行完成,你会发现,有一层的LinearLayout是没用的,通过merge标签,我们就可以轻松的解决这个问题。
<merge xmlns:android="http://schemas.android.com/apk/res/android">    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/add"/>    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/delete"/></merge>Now,当你通过include标签将一个布局文件嵌入另一个布局文件中,系统会忽略merge标签,直接将两个button元素放在布局文件中,来代替include标签的位置。作者有话说:如果您需要Android中文API,请扫一扫下面的二维码,您的关注,就是我的动力。
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: