您的位置:首页 > 其它

RadioButton左边设置图片大小,右边设置单选按钮大小的通用方法

2017-12-28 13:40 681 查看
public static void changeSize(int[] radio_buttons, int[] drawables, AppCompatActivity activity,int radio_button) {
if(radio_button!=0){

//这里radio_buttons是要设置的单选按钮,drawables是左边图片组,radio_button是单选按钮

for (int i=0;i<radio_buttons.length;i++){
RadioButton radioButton= (RadioButton) activity.findViewById(radio_buttons[i]);
Drawable thing_sign = activity.getResources().getDrawable(drawables[i]);
thing_sign.setBounds(0, 0, 50, 50);
Drawable radio_button_sign=activity.getResources().getDrawable(radio_button);
radio_button_sign.setBounds(0,0,50,50);
radioButton.setCompoundDrawables(thing_sign, null, radio_button_sign, null);
}
}else{
for (int i=0;i<radio_buttons.length;i++){
RadioButton radioButton= (RadioButton) activity.findViewById(radio_buttons[i]);
Drawable thing_sign = activity.getResources().getDrawable(drawables[i]);
thing_sign.setBounds(0, 0, 50<
9163
span style="color:#cc7832;">, 50);
radioButton.setCompoundDrawables(null, thing_sign, null, null);
}
}
}
}

附上radio_button的代码,供参考

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/radio_checked"/>
<item android:state_checked="false" android:drawable="@drawable/nothing"/>
</selector>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: