RadioButton的特定使用场景

来源:互联网 发布:网络延迟对网速的影响 编辑:程序博客网 时间:2024/06/04 19:16


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"      这两个是关键点


0 0
原创粉丝点击