3

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>
Linh
  • 57,942
  • 23
  • 262
  • 279
DkgMarine
  • 59
  • 6

1 Answers1

2

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! :)

AL.
  • 36,815
  • 10
  • 142
  • 281
  • I noticed that you have a `background` element and a `src` element. Is there a reason why you need to separate elements? If you are aiming to cover the ImageButton with an image, why not just set the `background` with the image itself. I tried it on my end where the `background` is set to the image you want. – AL. May 20 '16 at 02:19
  • No worries. Cheers! :D – AL. May 20 '16 at 02:27