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);