Set background image for all screen size

Put simple drawable folder, and paste your image there. Then open your styles.xml, and paste this line of code.

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorOrange</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@drawable/yourImage</item>
    </style>

By using this you don't have to put background images in every layout.


Convert you image in all below sizes and paste it in particular folder.

xxxhdpi: 1280x1920 px
xxhdpi: 960x1600 px
xhdpi: 640x960 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px

Are the best dimensions for the app to run in all devices.

Reference


Use an ImageView instead of just adding the image to some view's background. Using imageview won't stretch your image but just crop the not fitting part of the image. All this work done by the scaleType="centerCrop" tag.

Here's a sample code:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_class"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="lpt.com.attendance.ActivityClass.Activity_Class">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/background" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            //Now this is your main layout to put everything.

        </RelativeLayout>
</FrameLayout>