自定义View与merge节点
来源:互联网 发布:网络建站费用 编辑:程序博客网 时间:2024/06/06 12:36
之前写自定义ViewGroup的时候,一般都像下面:
public class TestView extends RelativeLayout { public TestView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } private void init(Context context) { LayoutInflater.from(context).inflate(R.layout.merge_test, this, true); }}
merge_test.xml如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/b1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/b2" android:text="aaa" /> <Button android:id="@+id/b2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="bbb" /></RelativeLayout>
这样实际上是有性能问题的,会产生一个RelativeLayout(TestView本身)套嵌另一个RelativeLayout(xml)的现象。
还有另外一个问题,如果使用TestView的measure、layout、draw等方法(不是onXXX),实际上只是直接作用在其子View(xml的RelativeLayout)上,可能有潜在问题。
合理的方法是将xml里的RelativeLayout改为merge。merge不会检查根View的attr,比如android:layout_below等等,所有东西完全可用。但是根View(TestView)本身的一些参数,要自己调用函数设置(比如,LinearLayout的Orientation)。
这样可以减少一层ViewGroup,还可以减少想当然的调用问题。
0 0
- 自定义View与merge节点
- 自定义流程节点View
- 使用merge标签自定义View
- Android 自定义节点流程View
- 自定义View的多节点实现
- 自定义View与ViewGroup
- 自定义View与ViewGroup
- View与ViewGroup分类以及自定义View
- 自定义view旋转与加载
- 自定义View基础与原理
- 页面指示器与自定义View
- 自定义View分类与流程
- 自定义View分类与流程
- 样式主题与自定义View
- 样式主题与自定义View
- Android:View滑动与自定义
- 样式主题与自定义View
- 用来显示物节点进度的自定义View
- 基于Servlet&Jsp的网上书店设计(一)
- LeetCode 30 Substring with Concatenation of All Words--In Java
- Ubuntu中安装oracle java和Eclipse
- uibutton点击按钮时title变大 松开时变小
- TLD学习之剥离Randrom Fern
- 自定义View与merge节点
- 欢迎使用CSDN-markdown编辑器
- 使用HttpClient进行远程接口测试
- CSAPP的二进制炸弹实验
- 二级域名session 共享方案
- java基础总结(四)
- 代理对缓存命令的支持
- C++学习笔记:MyString类的重载 练习
- iOS涂鸦画板 主要自定义UIView