Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 876
Andy A Avatar asked Oct 02 '22 19:10

Andy A


1 Answers

<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

like image 197
Pablo_Cassinerio Avatar answered Oct 12 '22 09:10

Pablo_Cassinerio