还不知道如何改变RadioButton中drawableTop的图片大小的可以看一下,思路简代码也少很好实现的。
首先说一下这些图片其实都是UI事先给咋们设计好的,基本情况不用我们去处理,直接用就可以。
好,那么当我们在练习的时候,图片不合适是不能直接改变不居中RadioButton的宽高来实现的就可能用得到!下面先看一看未经过动态修改的RadioButton中图片的大小。

这样一看就是不合适的,UI设计太low了
下面就是本篇的正题了。动态修改大小。
//定义RadioButton数组用来装RadioButton,改变drawableTop大小
rb = new RadioButton[3];
main_vp = (NoScrollViewPager) findViewById(R.id.main_vp);
main_rg = (RadioGroup) findViewById(R.id.main_rg);
//将RadioButton装进数组中
rb[0] = (RadioButton) findViewById(R.id.rb_home_page);
rb[1] = (RadioButton) findViewById(R.id.rb_community);
rb[2] = (RadioButton) findViewById(R.id.rb_mine);
//for循环对每一个RadioButton图片进行缩放
for (int i = 0; i < rb.length; i++) {
//挨着给每个RadioButton加入drawable限制边距以控制显示大小
drawables = rb[i].getCompoundDrawables();
//获取drawables,2/5表示图片要缩小的比例
Rect r = new Rect(0, 0, drawables[1].getMinimumWidth() * 2 / 5, drawables[1].getMinimumHeight() * 2 / 5);
//定义一个Rect边界
drawables[1].setBounds(r);
//给每一个RadioButton设置图片大小
rb[i].setCompoundDrawables(null, drawables[1], null, null);
}这样我们的图片就会修改成想要的效果!!下面看一下修改过后的效果

效果是不是非常完美,这样就恩能够实现了。
作者:wangchao0837