设置RadioButton的图片大小
/**
* 设置radiobutton图片大小
*/
private void setRadioButtonDrawable() {
RadioButton[] rbs = new RadioButton[3];
rbs[0] = btnHome;
rbs[1] = btnReport;
rbs[2] = btnMy;
for (RadioButton rb : rbs) {
//挨着给每个RadioButton加入drawable限制边距以控制显示大小
Drawable[] drawables = rb.getCompoundDrawables();
//获取drawables
Rect r = new Rect(0, 0, drawables[1].getMinimumWidth() * 2 / 3, drawables[1].getMinimumHeight() * 2 / 3);
//定义一个Rect边界
drawables[1].setBounds(r);
//添加限制给控件
rb.setCompoundDrawables(null, drawables[1], null, null);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
上次更新: 2024/01/12, 11:30:32