Andy A Andy A - 4 months ago 10
Android Question

Making Android src image resource fill button area

I have the following XML:

<ImageButton
android:id="@+id/SwapTextButton"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="0.5"
android:background="@drawable/my_gradient_button"
android:scaleType="fitCenter"
android:src="@drawable/extended_text" />


And it outputs a button which looks like this:

Button text too small

Is there any way to increase the size which the src resource takes up? By that I mean maintain the src within the area of the button, but make it larger than it is now.

I have tried changing the scaleType, but any other setting causes the src resource to display parts of itself outside the button boundary (aka it becomes too large).

I've had a research and there seems to be solutions based in java, but ideally I'd like to keep the solution in xml too.

Can someone suggest a fix/point me in the right direction?

Thanks

Answer
<ImageButton
android:id="@+id/SwapTextButton"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="0.5"
android:background="@drawable/my_gradient_button"
android:scaleType="fitXY"
android:src="@drawable/extended_text" />

Try this, fitXY for scaletype should "fill" your ImageButton