Centering a background image in Android
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>
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.