Android merge

The <merge /> tag helps eliminate redundant view groups in your view hierarchy when including one layout within another. For example, if your main layout is a vertical LinearLayout in which two consecutive views can be re-used in multiple layouts, then the re-usable layout in which you place the two views requires its own root view. However, using another LinearLayout as the root for the re-usable layout would result in a vertical LinearLayout inside a vertical LinearLayout. The nested LinearLayout serves no real purpose other than to slow down your UI performance.


<合并/ >标记有助于消除冗余在视图层次结构视图组其中一个在另一个布局。例如,如果您的主要布局垂直LinearLayout连续两个视图可以重复使用在多个布局,然后你把两个视图的可重复使用的布局需要自己的根视图。然而,使用另一个LinearLayout作为可重用的布局将导致根垂直LinearLayout在一个垂直的LinearLayout。嵌套的LinearLayout以外没有任何作用减缓UI性能。


LayoutInflater遇到这个标签时,它会跳过它,并将<merge />内的元素添加到<merge />的父元素里。


<merge />标签极其有用。然而它也有以下两个限制:

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

·         当Inflate<merge />开头的布局文件时,必须指定一个父ViewGroup,并且必须设定attachToRoottrue(参看inflate(int, android.view.ViewGroup, Boolean)方法)。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值