0

I have made a button and then added some text and an image into it however the image size is too large for the button. I would like to make the image smaller is there any way of doing this.

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:layout_centerVertical="true"
    android:background="@drawable/curvebutton"
    android:drawableLeft="@drawable/Mechanic"
    android:cropToPadding="false"
    android:scaleType="fitXY"
    android:padding="10dp"
    android:text="@string/broke_down"
    android:textColor="#ffffff" />

enter image description here

Craig Gallagher
  • 235
  • 1
  • 5
  • 19

1 Answers1

0

This can be done in code. As explained in this SO post, you can do it in the following way. I tested this code and it works.

Drawable drawable = getResources().getDrawable(R.drawable.ic_face_black);// Use your image
        drawable.setBounds(0, 0, (int)(drawable.getIntrinsicWidth()*0.5),
                (int)(drawable.getIntrinsicHeight()*0.5));
        ScaleDrawable sd = new ScaleDrawable(drawable, 0, 90, 90);
        Button btn = (Button) findViewById(R.id.button);
        btn.setCompoundDrawables(sd.getDrawable(), null, null, null);
Community
  • 1
  • 1
Swagata Acharyya
  • 647
  • 4
  • 10