8

I have four radio button.

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>

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?

SaeHyun Kim
  • 475
  • 2
  • 8
  • 26

4 Answers4

8

Sclae the button

<RadioButton
        android:scaleX="0.75"
        android:scaleY="0.75" />
Heena Arora
  • 739
  • 8
  • 18
3

Finally found the correct solution :

Step 1 : Use your @drawable/selected_btn or @drawable/nonselected_btn as an INSET DRAWABLE .

Step 2 : Provide padding as desirous.

Step 3 : Yuhuuuu !! You've decreased the size of the radio button image.

Sarasranglt
  • 3,819
  • 4
  • 23
  • 36
0

If you want to do it correctly , you should resize your assets accordingly. Otherwise, i'm not sure how to drecrease the button image size without decreasing the button by itself

FOliveira
  • 558
  • 4
  • 9
0

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

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);
}
SaeHyun Kim
  • 475
  • 2
  • 8
  • 26