为何要使用<merge\>标签

来源:互联网 发布:http连接数据库 编辑:程序博客网 时间:2024/06/13 06:03

在使用include复用layout时,可能复用的layout有个view group,然后这个view group又被嵌套别的view group里,这样就增加了view的深度,影响运行的速度,而这种嵌套不是必须的。

因此可以使用<merge\>标签,它将它里面嵌套的view直接include到其父layout中,而没有再加一层view group,因此减小了深度,提高了速度


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>