Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set background image for all screen size

I'm working with a project to set background image for all screen size with same image . How is it possible? How to set background image for all screen size in android studio? How we can put folder in drawable?

like image 919
Jincy Avatar asked Jan 24 '17 06:01

Jincy


3 Answers

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

like image 98
sivaBE35 Avatar answered Sep 22 '22 15:09

sivaBE35


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.

like image 33
Aman Shekhar Avatar answered Sep 25 '22 15:09

Aman Shekhar


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>
like image 26
Karun Shrestha Avatar answered Sep 25 '22 15:09

Karun Shrestha