Android代码中实现勾选框

        RadioGroup cRadio = new RadioGroup(this);
        LinearLayout.LayoutParams cRadioParams =new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
        cRadioParams.leftMargin = 16;
        cRadioParams.setLayoutDirection(LinearLayout.VERTICAL);

 

        RadioButton cRadioBtn_1 = new RadioButton(this);
        cRadioBtn_1.setClickable(false);
        LinearLayout.LayoutParams cRadioBtnParams_1 =new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
        cRadioBtn_1.setMinHeight(40);
        cRadioBtn_1.setTextSize(16);
        cRadioBtn_1.setBackground(getResources().getDrawable(R.drawable.radio_bg));//图片        
        cRadioBtn_1.setButtonDrawable(getResources().getDrawable(android.R.color.transparent));//button="@null"
        //drawableLeft
        Drawable drawableLeft_1 = getResources().getDrawable(R.drawable.radio_bg_img);//图片
        cRadioBtn_1.setCompoundDrawablesWithIntrinsicBounds(drawableLeft_1,null,null,null);
        cRadioBtn_1.setCompoundDrawablePadding(4);
        cRadioBtn_1.setPadding(8,8,8,8);
        cRadioBtn_1.setText("A、");
        //默认选中
        cRadioBtn_1.setChecked(true);
        

 添加到RadioGroup 布局中

 cRadio.addView(cRadioBtn_1,cRadioBtnParams_1);

添加到xml的布局中

           <LinearLayout
                android:id="@+id/activity_examination_completionLinearLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
            </LinearLayout>
 mView.addView(cRadio,cRadioParams);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值