Keep Coding

android, django, windows, xml, algorithm.

android

How to have an image embedded on an image button scale to the size of the image

I am attempting to create a calculator app, I would like to use an image button to allow the user to select what they want to calculate. I want to use this image for the 0 button (zero button image). Currently when I add the image to the user interface, it is cropped like this (cropped zero image). Is there a way to allow the image to scale to the size of the button when I resize the button? Thank you!
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lontronix.calculator.Calculator">
<TextView
android:id="#+id/textView"
android:layout_width="500dp"
android:layout_height="125dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="#string/Filler_Text"
android:textSize="35pt" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="250dp"
android:layout_height="150dp"
app:srcCompat="#drawable/zero"
android:layout_marginStart="50dp"
android:layout_marginBottom="42dp"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

write these properties on your imageView.
android:adjustViewBounds="true"
android:scaleType="fitXY"
Or you can try a different scaleType, see below:
https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide