Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting resized images inside Android buttons

I want to design a TableLayout with some big buttons with icon and text embbeded. I have found some similar question but not the same 1. My simplified XML layout is:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:id="@+id/TableRow01" android:gravity="center">
<Button android:text="@string/telephone" android:drawableTop="@drawable/phone" android:id="@+id/button_phone"></Button>
<Button android:text="@string/help" android:src="@drawable/help" android:id="@+id/button_help"></Button>
</TableRow>
</TableLayout>

The icon images are a little big, so I want to Android resizes them but the android:height parameter resizes the button, not the embedded image. Do you any idea to get an Button with Text and Image "resizeable"?

like image 907
Jaime M. Avatar asked Dec 18 '25 08:12

Jaime M.


1 Answers

Use the ScaleType attribute (Documentation)
EDIT: See here for information on supporting multiple screen sizes with your drawables. If you follow the android conventions instead of trying to just use really large drawable and resize them at runtime for smaller screens, you'll have much better perfomance and fewer issues.

like image 186
QRohlf Avatar answered Dec 20 '25 22:12

QRohlf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!