Documente Academic
Documente Profesional
Documente Cultură
Stack Overflow
Questions Tags Users Badges Unanswered Ask
74
background
imageview
framelayout
I see many applications that use a full-screen image as background. This is an example:
log in
I want to use this in a project, the best way I've found so far to do this is to use an image with a large size, put it in a ImageView and use android:
adjustViewBounds="true" to adjust the margins
The problem is that if a screen with a very high resolution, the image falls short.
Another option I thought of is to use the image in a FrameLayout, with match_parent in width and height as background... this stretches the image, but I think
the result is not very good.
I can ask how would you do it?
Thanks in advance Regrads
share
Asked
Apr 21 '13 at 20:40
user1987392
1,797 2 17 38
Edited
Feb 16 '14 at 18:17
Don't believe this works on backgrounds, but it should work on images. android:scaleType="centerCrop" EGHDK Apr 21 '13 at 20:59
add a comment
7 Answers
98
Option 2:
Order By
Votes
Add a single large image. Use FrameLayout. As a first child add an ImageView. Set the following in your ImageView.
android:src="@drawable/your_image"
android:scaleType = "centerCrop"
share
Answered
Apr 22 '13 at 3:39
Community
1
Edited
Dec 9 '13 at 4:18
In the res->drawable folders. There may be multiple - each stand for a different resolution (ex. low resolution/high resolution). If you don't have specific images for each resolution,
any one will work. krodmannix May 27 '14 at 23:52
The answer is good. But i wonder if someone found the typical phone sizes for each dpi group, which would be quite useful when preparing images. Edited: found stackoverflow.com/questions/10574363/ fox Jun 19 '14 at 13:15
Wouldn't mixing option 1 and 2 be the best option? Lay Gonzlez Oct 14 '14 at 15:46
show 5 more comments
14
Another option is to add a single image (not necessarily big) in the drawables (let's name it backgroung.jpg), create an ImageView
iv_background at the root of your xml without a "src" attribute. Then in the onCreate method of the corresponding activity:
share
Answered
Aug 9 '14 at 13:43
This is a useful solution, but remember to do bitmap processing off of the main thread: developer.android.com/training/displaying-bitmaps/ Kyle Ivey Sep 22 '14 at 21:47
add a comment
You should put the various size images into the followings folder
for more detail visit this link
ldpi
mdpi
hdpi
xhdpi
xxhdpi
and use RelativeLayout or LinearLayout background instead of using ImageView as follwoing example
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/your_image">
</RelativeLayout>
share
Answered
Apr 22 '13 at 6:16
m vai
7,253 4 24 74
Edited
Jun 13 '15 at 18:06
I'm getting an error that Unexpected namespace prefix "xmlns" found for tag RelativeLayout CodyBugstein Jun 18 '14 at 11:59
Is this in mitmap? Ruchir Baronia Nov 11 '15 at 18:43
@rich its drawable Munish Kapoor Nov 12 '15 at 2:58
add a comment
What about
android:background="@drawable/your_image"
share
NoToast
358 2 13
share
In lines with the answer of NoToast, you would need to have multiple versions of "your_image" in your res/drawable-ldpi,mdpi, hdpi, x-hdpi (for
xtra large screens), remove match_parent and keep android: adjustViewBounds="true"
Answered
Apr 21 '13 at 20:54
Answered
Apr 22 '13 at 4:29
share
use this
android:background="@drawable/your_image
Answered
Jan 3 '15 at 17:54
share
Answered
Nov 12 '14 at 13:46
Yawar
685 2 8 26
Edited
Dec 21 '15 at 16:52
Your Answer
log in
or
Name
By posting your answer, you agree to the privacy policy and terms of service.
meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app
2016 Stack Exchange, Inc