自定义控件从xml获取属性值的优雅写法
来源:互联网 发布:ajax javascript区别 编辑:程序博客网 时间:2024/06/06 04:13
public LinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { Properties properties = getProperties(context, attrs, defStyleAttr, defStyleRes); setOrientation(properties.orientation); .... } public static Properties getProperties(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { Properties properties = new Properties(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, defStyleAttr, defStyleRes); properties.orientation = a.getInt(R.styleable.RecyclerView_android_orientation, VERTICAL); properties.spanCount = a.getInt(R.styleable.RecyclerView_spanCount, 1); properties.reverseLayout = a.getBoolean(R.styleable.RecyclerView_reverseLayout, false); properties.stackFromEnd = a.getBoolean(R.styleable.RecyclerView_stackFromEnd, false); a.recycle(); return properties; } public static class Properties { /** @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_android_orientation */ public int orientation; /** @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_spanCount */ public int spanCount; /** @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_reverseLayout */ public boolean reverseLayout; /** @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_stackFromEnd */ public boolean stackFromEnd; }
0 0
- 自定义控件从xml获取属性值的优雅写法
- 在自定义控件中读取XML配置属性的值
- Android--自定义控件的xml属性
- Android--自定义控件的xml属性
- android 自定义控件的XML属性
- 获取attrs.xml中声明的自定义属性的值
- ASP.NET2.0自定义控件属性的写法
- android无法获取自定义控件的属性值?
- Android自定义控件:如何使用自定义的XML属性
- Android自定义控件:如何使用自定义的XML属性
- android中自定义的控件,使用自定义属性attrs.xml
- xml属性值的获取
- XML工具代码:SAX从String字符串XML内获取指定节点或属性的值
- 自定义控件的属性(attrs.xml,TypedArray)的使用
- 自定义控件的属性(attr.xml,TypedArray)的使用
- [Android xml]自定义控件的属性-declare-styleable
- android自定义控件属性——attr.xml的使用
- 自定义控件的属性attr.xml,declare-styleable,TypedArray
- Java单机版五子棋
- 剑指offer 面试题50 树中两个节点的最低公共祖先
- ACM刷题之HDU————How Many Trees?
- 【技术架构】单点系统架构的可用性与性能优化
- setTimeout定时工具
- 自定义控件从xml获取属性值的优雅写法
- 最简总结 -- 梯度下降算法
- poi之excel导入
- 浅谈Java设计模式(十二)享元模式(Flyweight)
- vs2010在输出窗口输出调试信息
- Andriod 从源码的角度详解View,ViewGroup的Touch事件的分发机制
- 注册表中Service关键设置的完整说明
- C++中的对齐方式及sizeof小结
- cf 87 A