Centering source image (android:src) for ImageButton in Android

Published by Igor Khrupin on

For centering android:src in the ImageButton I use the next solution.

First I need create 9-patch src image using next rules. Please look at the screenshot from draw9patch utility from Android SDK.

draw9patch utility

draw9patch utility

Next you need add the 9-patch image into ImageButton like this:

android:src="@drawable/src_image" />

And finally you will get the next screen:

Result screen

Result screen

Download it from github


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.