RadioButton的图片大小设置

在RadioButton使用中,可能需要放入图片,但是XML中无法直接设置图片的大小。

<RadioButton
    android:gravity="center"
    android:id="@+id/rb_first"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:button="@null"
    android:drawableTop="@drawable/selector_ic_first"
    android:text="首页"/>
<RadioButton
    android:gravity="center"
    android:id="@+id/rb_search"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:button="@null"
    android:drawableTop="@drawable/selector_ic_search"
    android:text="查询"/>
<RadioButton
    android:gravity="center"
    android:id="@+id/rb_me"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:button="@null"
    android:drawableTop="@drawable/selector_ic_people"
    android:text="我的"/>
效果图:可以发现图片太大了


如何设置图片大小:

Java代码实现:

初始化使用ButteerKnife插件

@BindView(R.id.rb_first)
RadioButton rbFirst;
@BindView(R.id.rb_search)
RadioButton rbSearch;
@BindView(R.id.rb_me)
RadioButton rbMe;

private void changeImageSize() {
    //定义底部标签图片大小
    Drawable drawableFirst = getResources().getDrawable(R.drawable.selector_ic_first);
    drawableFirst.setBounds(0, 0, 69, 69);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度
    rbFirst.setCompoundDrawables(null, drawableFirst, null, null);//只放上面

    Drawable drawableSearch = getResources().getDrawable(R.drawable.selector_ic_search);
    drawableSearch.setBounds(0, 0, 69, 69);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度
    rbSearch.setCompoundDrawables(null, drawableSearch, null, null);//只放上面

    Drawable drawableMe = getResources().getDrawable(R.drawable.selector_ic_people);
    drawableMe.setBounds(0, 0, 69, 69);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度
    rbMe.setCompoundDrawables(null, drawableMe, null, null);//只放上面
}
效果图:设置大小后,图片变小了





  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值