在RadioGroup里动态添加RadioButton,通过以下代码添加
RadioButton radioButton = new RadioButton(refView.get().getActivity()); radioButton.setBackgroundResource(R.drawable.ghsj_button);
group.addView(radio);
页面效果并不是很好,背景图片还会拉伸,试了很多方法没有效果
后来想到一种方案,结合xml使用
<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/radio_btn_selector"
android:paddingLeft="5dp"
android:textColor="#ffffffff"
android:textSize="@dimen/dp_17"
android:gravity="center_vertical">
</RadioButton>
RadioButton radio = (RadioButton) LayoutInflater.from(refView.get().getActivity()).inflate(R.layout.radiobtn_item,activateActivity.group,false);
group.addView(radio);
问题解决