user4514473 user4514473 - 1 year ago 193
Android Question

How to scale drawable inside button so that the button size is not controlled by the drawable?

In the screenshot below I'm using the same icon for both the button and the imageview but what I can't seem to control is the scaling of the icon inside the button, I can make the icon smaller by reducing the resolution and make the button smaller but that makes the icon pixelated. Is there any way to have high resolution icons with buttons and let the button control the overall size?

enter image description here

XML for the button:


Answer Source
Drawable emailImg = getResources().getDrawable(R.drawable.email2);
        drawable.setBounds(0, 0, (int)(drawable.getIntrinsicWidth()*0.1),
        ScaleDrawable scaledImg = new ScaleDrawable(emailImg, 0, 10, 10);
        Button button = (Button)findViewById(;
        button.setCompoundDrawables(scaledImg.getDrawable(), null, null, null);

Try this

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download