如何减少单选按钮的可绘制尺寸?

时间:2015-05-25 11:23:10

标签: android

我有四个单选按钮。

xml source

<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的按钮图像尺寸 可能吗?

4 个答案:

答案 0 :(得分:7)

按下按钮

<RadioButton
        android:scaleX="0.75"
        android:scaleY="0.75" />

答案 1 :(得分:0)

如果您想要正确执行此操作,则应相应调整资源大小。否则,我不确定如何在不减少按钮的情况下降低按钮图像大小

答案 2 :(得分:0)

我无法找到解决方案 但我找到了另一种解决方案。

xml source

<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);
}

答案 3 :(得分:0)

终于找到了正确的解决方案:

第1步: 使用 @ drawable / selected_btn @ drawable / nonselected_btn 作为INSET DRAWABLE

第2步: 希望提供填充。

第3步: Yuhuuuu !!您减小了单选按钮图像的大小。