布局中@null的代码实现方式
? ?布局中通常会用到@null。如RadioButton常用的技巧通过RadioGroup实现Tab,需要设置android:button="@null"。如果要在代码中动态创建控件,android中并不能找到相关的属性或方法。搜索均无解决办法,最后想到一个变通的方法:通过透明色获取drawable。
?
再在代码生成RadioButton
?
RadioButton rb =(RadioButton)LayoutInflater.from(getContext()).inflate(R.layout.rb, null);?这种方式的好处是样式等属性可以在布局中统一指定省的查sdk寻找相关属性的设置方法。
1 楼 nocb 2012-01-05 非常感谢 受用了 2 楼 lorrycat 2012-04-16 太感谢了,解决了一个大难题!!!!!