Search code examples
androidsplash-screen

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>

Solution

  • You don't actually need neither LinearLayout nor RelativeLayout here, use a more lightweight FrameLayout instead.

    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:src="@drawable/splash"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    
    </FrameLayout>