如何减小单选按钮的可绘制大小? [英] How to decrease radio button drawable size?

查看:60
本文介绍了如何减小单选按钮的可绘制大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个单选按钮.

<RadioButton
    android:id="@+id/fragBtn1"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:background="@drawable/btn_bg_selector"
    android:button="@null"
    android:drawableTop="@drawable/btn_img_selector" />

btn_img_selector

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/selected_btn" android:gravity="center" android:state_checked="true"/>
    <item android:drawable="@drawable/nonselected_btn" android:gravity="center"/>
</selector>

btn_bg_selector

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/btnPressed" android:state_pressed="true"/>
    <item android:drawable="@color/btnNonPressed"/>
</selector>

但是按钮图像太大.
我只想减小按钮的图像大小.(不减小按钮的大小)
例如,我要缩放按钮图像尺寸30px * 30px.
可能吗?

But button image is too big.
I want to decrease a button image size only..(not decrease button size)
For example, I want to scale a button image size 30px * 30px.
Is it possible?

推荐答案

我找不到解决方案.
但是我找到了另一个解决方案.

I can't find a solution.
But I find a another solution.

<RadioButton
    android:id="@+id/fragBtn1"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:background="@drawable/btn_bg_selector"
    android:button="@null"
    android:drawableLeft="@drawable/btn_selector" />

MyActivity.java

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    BitmapDrawable bd = (BitmapDrawable) this.getResources().getDrawable(R.drawable.mybtn);

    int iconWidth = bd.getBitmap().getWidth();
    int leftPadding = (btn.getWidth() / 2) - (iconWidth / 2);

    btn.setPadding(leftPadding, 0, 0, 0);
}

这篇关于如何减小单选按钮的可绘制大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆