I have a background image about 100 x 100 that I want to center in an Android app. Is there a way to do this?
I'm thinking it would greatly help with orientation changes for simple apps.
You can use BitmapDrawable for the case. Create centered.xml in res/drawable
folder:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/your_image" android:gravity="center"/>
Then you can use centered
drawable as background.
Or if you want to use your mipmap
image, you should use item
instead of bitmap
:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/app_bg_color" /> <item android:drawable="@mipmap/ic_launcher_round" android:gravity="center"/> </layer-list>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With