I want to set a background image in my app, which will fill all screen and scale if needed, so I set it in my main_layout.xml like that:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:id="#+id/imageView"
android:src="#drawable/bg_iphone_6_plus" />
and it looks like this
not very good, I need this picture to adjust in width too, actually.
ok, so this works in most cases and with all API's higher 16, but when I run my app on api lower 16 ( minTargetSdk=14 ), I see this:
I have no idea why it shows like that, I have already tried this tutorial, and replaced ImageView with com.inthecheesefactory.thecheeselibrary.widget.AdjustableImageView
but it didn't change anything at all
If your background image is only this gray picture with gradient in the middle, then move the drawable to android:background to parent container. You don't need additional ImageView for that.
But, if you want to set bitmap as background and keep ratio of this image on different devices and orientations, you should use ImageView and its android:scaleType with e.g. "centerCrop" (which usually is the best choice for backgrounds).
Try with replacing android:src property with android:background in your ImageView layout. I think that will solve your issue. If it is still causing the issue then please let me know.
Related
I get some images of our new designer but found it strange some of them look like this:
I'm trying to overcome it as it displays well on his device and normal image viewer or PC so while I try I found that if I used src if fit one that has clipped from the right and left (this while using background)
however, if I used src it get fit correctly.
some others (using background)
also, I used src it fits correctly.
I'm confused about this issues and can't find a clarification for it when I googled it.
Code For ImageView
<ImageView
android:id="#+id/aa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/a123"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
Hope anyone can suggest me a way to handle them programmatically and how to persuade designer it is from him if it is?
Hope also someone declares me the core of when using src or background
I don't understand what is your problem exactly.
However,backgroundis for simply defining a shape,color,pattern or anything for our View or Layout.
So you can use this attribute for every layout and button or TextView or anything.
Let's say you have created a Circle.xml file which is a shape.If you call background="#drawable/circle" you can make your ImageView to have a Circular shape.
With src in an ImageView for example you put your Image in the ImageView.
You also can adjust the height and width of the displayed image by layout_width or layout_height which you can set both to "Wrap_content" or "match_parent" or any value
For fitting the image the way you want you should play with layout height and width and layout margin values!
1) I was facing the same issue i fixed it by using android:scaleType="fitXY" it will fit the image accordingly but if you use too small image it will be distorted and if you
will use raw image file make sure to use Compressed image without disturbing the
image quality.
2) All views can take a background image.
The src to an ImageView has additional features:
different scaling types
adjustViewBounds for setting bounds to match image dimensions
some transformations such as alpha-setting
And more that you may find in the docs.Source
So I'm working on Pacman for Android as a learning exercise. I've got the background set in my activity layout, but I'm having trouble making the background fit properly.
I've tried centerCrop and fitXY, with different results, neither of which work exactly. I want to stretch the view to the dimensions of the screen. It appears however that the image view is restricted to the center, like I have 3 imageviews ... but I have only one.
Any thoughts? Do I have to do some of this in code?
Thanks!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000FFF"
tools:context="srg.pmd.GameActivity"
>
<ImageView
android:id="#+id/emptyPacman"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/blank_screen"
android:scaleType="fitXY"
/>
First screenshot is fitXY
Second is centerCrop
The image you are using must be 320x480 then only the image will fit the screen other wise it will get distorted here is a link for more info about the image size Android: Background Image Size (in Pixel) which Support All Devices .hope it works for u
Well, nuts to me. The actual png file was wrong -- it was a lot wider than I assumed. Taking a closer look with an image editor revealed the problem.
I've been trying to find an answer to this all of last evening with no luck so I decided to come ask here. I just started getting into front end dev for Android apps and I'm trying to do something really simple that just doesn't work. All I want to do is add an image on the screen and be able to resize it EXACTLY what size I want regardless of proportions. This is the code I'm currently using inside a relative layout:
<ImageView
android:layout_width="400dp"
android:layout_height="200dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/statsus_logo" />
My image is a horizontal rectangle. When I first add it, it shows up inside a small square centered with a bit of padding all around. When I make the width 400dp that square appears to strech almost 100% across the screen however the logo stays the EXACT same size, centered vertically and horizontally inside this imageview container. When I increase the height of the imageview, the logo increases its size but almost as if it was taking the height and using it as a width. I feel like what its trying to do right now is use the height as its width and the only time when its width is the value i put in, is if the height is also the same value and even then there's some extra unwanted padding.
Again, all I want is for this damn image to be the size I tell it to, so if I want it 5dp wide and 100dp tall, it does just that. Can anyone please help? Thank you very much in advance.
Try to add this attribute to your imageview
android:scaleType="fitXY"
Scale type reference
android:scaleType="fitXY" is the way to scale your image however you want without keeping your proportions however my issue was a little bit different... I'm using android studio and for some reason the settings I was using to "add a new image asset" was making my image act the way I described it above... if I just add an image manually by just click and dragging into the folder, then the image works the way I want it... so long story short, the issue was with how I added my new image asset
thanks to everyone for all of your answers and help!
I have an activity that includes a striped background image. Click to enlarge – this is the original image I'm using. There's also a version with a logo for another activity.
It looks fine as is. I set it as a background in the activity through XML, something like this.
I need the hack as an ImageView to be able to properly centerCrop a logo in the background, but this is irrelevant to the issue, as it persists when setting the background for the RelativeLayout and removing the ImageView.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/background_striped" />
Note that since there has to be a logo inside the image, I can't stretch it artificially or have it repeat.
In the layout preview screen, it looks like this:
In the emulator, it looks like this:
As you can see, it looks quite bad, compared to how I'd expect it:
Naturally, I've created versions of the striped background for all display resolutions (from ldpi to xhdpi), but they always seem to be scaled in a pretty bad way.
Is there any way to get the background scaled in a higher quality? Just using the xhdpi version won't result in better quality—it will just make the scale result worse and more washed out.
For scalable drawables it is better to use a 9-patch. You can create one with your small striped background image using the android 9-patch tool:
http://developer.android.com/tools/help/draw9patch.html
Try using repeat. I tested it and it seems to look fine.
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background_striped"
android:tileMode="repeat" />
I currently working on my personal project in Android. I'm quite a newbie in android development well it's been a months since I've started to self study this but I just can't focus on this one. Well, so here's my problem, first I will discuss what I've made so far:
I've placed a 6 ImageView for each tableRow (six table rows) in a table layout which make it a 6x6 ImageView.
each of the imageView has a default image icon (the default icon from the android drawable).
Once I clicked the ImageView I will change it's Image using setImageDrawable.
the default icon of the android is sized smaller than the images I've placed in which I think 36x36 pixels is the default icon (the android default) wherein my images are in size of 80x80 pixels.
Now here's the problem:
Once I've clicked the image it will successfully changes the image but will also resize the imageView into the size of my image(80x80 px).
well how do I get over this? I've tried setting the ImageView's scale type into fitXY but it has done nothing still my the imageView is resized.
I've also tried changing the wrap_content into fill_parent but nothing also happens (well I just think that it may solve the problem lol)
Here's the property of my ImageView:
<ImageView android:scaleType="fitXY"
android:id="#+id/imageView1"
android:src="#drawable/image0"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</ImageView>
Any help please? Thanks in advance!
you can set the fix size for the image view into the xml file or by coding through for e.g. here in xml file
<ImageView android:scaleType="fitXY"
android:id="#+id/imageView1"
android:src="#drawable/image0"
android:layout_height="90dp"
android:layout_width="120dp">
</ImageView>
so all image are display with the size 120*90 so when you change the picture it will fit into this imageview