Reputation: 115
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?
Upvotes: 7
Views: 19072
Reputation: 668
this same feature need in my projects so in this case, we have two option
1) Put image in respective res folder hdpi to xxxhdpi and load but in this case, we have to maintain all the 7-8 image for single item.
another solution is
2) Make responsive html with tested in all screen compatible and put in raw folder in assets and load url in webview which shold same as image view if you need image view click event you can use webview touch event.
both solution are working fine earlier we are using method 1 but now we move on 2nd one due to reduce some memory and handling issue. If still have any confusion please ask...
Upvotes: 0
Reputation: 733
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>
Upvotes: 3
Reputation: 1891
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.
Upvotes: 9
Reputation: 2780
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.
Upvotes: 7