格局中@null的代码实现方式
2014-05-27 15:00
141 查看
布局中通常会用到@null。如RadioButton常用的技巧通过RadioGroup实现Tab,需要设置android:button="@null"。如果要在代码中动态创建控件,android中并不能找到相关的属性或方法。搜索均无解决办法,最后想到一个变通的方法:通过透明色获取drawable。
实际还是可以通过布局的方法来动态创建控件。先创建一个RadioButton的rb.xml
再在代码生成RadioButton
RadioButton rb =(RadioButton)LayoutInflater.from(getContext()).inflate(R.layout.rb, null);
这种方式的好处是样式等属性可以在布局中统一指定省的查sdk寻找相关属性的设置方法。
setButtonDrawable(getResources().getDrawable(android.R.color.transparent))
实际还是可以通过布局的方法来动态创建控件。先创建一个RadioButton的rb.xml
<?xml version="1.0" encoding="utf-8"?> <RadioButton xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@null" > </RadioButton>
再在代码生成RadioButton
RadioButton rb =(RadioButton)LayoutInflater.from(getContext()).inflate(R.layout.rb, null);
这种方式的好处是样式等属性可以在布局中统一指定省的查sdk寻找相关属性的设置方法。
相关文章推荐
- 格局中@null的代码实现方式
- 格局中@null的代码实现方式
- 格局中@null的代码实现方式
- 布局中@null的代码实现方式
- 布局中@null的代码实现方式
- 布局中@null的代码实现方式
- 布局中@null的代码实现方式
- 布局中@null的代码实现方式
- 布局中@null的代码实现方式
- ASP.NET中代码内嵌和代码后置的区别与实现方式
- javascript面向对象的方式实现的弹出层效果代码
- 网页刷新代码-刷新页面实现方式总结篇
- 尽管普通的sql语句代码可以实现数据插入的操作,但是更好的代码应该是参数的方式:
- 两种版本实现C#获取快捷方式目标路径的代码
- eclipse中通过接口查找它的实现,代码展开快捷方式
- Linux下关机的代码实现方式
- listView扩展2——java代码方式实现animation动画输出
- iphone上swipe操作方式的代码实现
- 使用重载方式实现继承体系的代码重用
- entlib 5.0学习笔记 通过代码方式实现注入