Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Center splash screen image

I have an app with a splash screen and the splash screen looks good on small devices but looks screwed up in a big tablet(emulator). so I changed the background to wrap_content. but it looks aligned to the side of the screen, Can some one tell me a way to center background images? here is my splash.xml-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/splash">
</LinearLayout>
like image 517
notnavindu Avatar asked Mar 04 '26 18:03

notnavindu


1 Answers

I am using a background image for my activity. First create a theme in your styles.xml:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

Then create a new drawable with the name background_splash.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/colorWhite"/>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/logo_splash"/>
    </item>
</layer-list>

Then set your activity to use this theme in your AndroidManifest.xml:

<activity android:name="SplashActivity" android:theme="@style/SplashTheme" >

This worked for me.

like image 144
kuffel Avatar answered Mar 07 '26 08:03

kuffel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!