DkgMarine DkgMarine - 6 months ago 29
Android Question

How to resize Image to button?

So I have an

ImageButton
but the image is a very big fit for it. I tried
android:scaleType="center"
and it failed because the image centered but it was too small and tried
fitXY
but same result.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f1e8e8"
tools:context="com.example.bassam.myapplication123.MainActivity">
<ImageButton android:id="@+id/myButton"
android:layout_width="match_parent"
android:layout_height="150dp"
android:padding="100dip"
android:background="#ffffff"
android:src="@drawable/Work"
android:scaleType="fitXY"
></ImageButton>
</RelativeLayout>

Answer

If how I understand your concern is correct, you simply just want to have the image scale to the size of the ImageButton itself, simply use

android:scaleType="fitCenter"

The image is adjusted depending on the size of the ImageButton. Try it out and let me know if it works. Cheers! :)