Search code examples
androidandroid-layoutlayoutsplash-screen

Background image is compressed in nexus 5 android


I have an image for splash screen of size equals to Nexus-5 dimension (1080 x 1920 pixels). Now When I add this image in background of LinearLayout, it seems to be compressed, here is the code

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical" android:layout_width="fill_parent"
          android:background="@drawable/app_bg"
          android:layout_height="fill_parent">

           <!-- 
              <ImageView android:id="@+id/splash_screen" 
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:background="@drawable/app_bg"
               android:layout_gravity="center"/>
           -->

     </LinearLayout>

Real image is

enter image description here

and attached is the screen shot from nexus-5

enter image description here


Solution

  • For setting the image as background you show, you should use image view as below, and use android:scaleType="centerCrop" and frame layout is best for this purpose.

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <ImageView 
        android:id="@+id/background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop">
    </ImageView>  
    

    Thanks