您的位置:首页 > 其它

RadioButton的特定使用场景

2016-02-26 17:48 190 查看
1 使用场景:

      结合radioGroup实现类似微信底部导航的效果




2 使用问题:

          我是用纯代码动态添加radioButton  ,  根据需求  需要去掉button

RadioButton button;
for (int i = 0; i < titleNames.length; i++) {
button = new RadioButton(context);
// 隐藏左侧  button
button.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
........
addView(button, params);
}


在高版本上显示没有问题,在低版本上(如<=16)就会出现下面情况



3 解决办法:

   就算纯代码添加radiobutton    ,radiobutton的对象的创建也要从xml中引用(期待大神的别的解决方案)

RadioButton button;
for (int i = 0; i < titleNames.length; i++) {
//            从xml  引用
button = (RadioButton) View.inflate(getContext(), R.layout.but,null);

addView(button, params);
}


<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:button="@null"
android:background="@null"
>
</RadioButton>


 android:button="@null"

    android:background="@null"      这两个是关键点
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: