I have a background image in body.
What I want to achieve is that:
1) - Calculate the visitor screen resolution.
2) - based on that resolution I want to resize my background image.
I know get the screen resolution as a
Display display = getWindowManager().getDefaultDisplay();
width_screen = display.getWidth();
height_screen = display.getHeight();
But I don't know how to resize the images according screen resolution of user.
Can anyone help?
Thanks..
Put a ImageView in your layout file and set
android:layout_width="match_parent"
android:layout_height="match_parent"
If you want to keep the aspect use:
android:scaleType="centerInside"
If you dont care about the aspect ratio use:
android:scaleType="fitXY"
you may have to write a custom view to do this. Overide onDraw method in it to copy your bitmap as many times as needed.
Related
What i need is that image should be scaled till it retains the exact proportions after that it should not be scaled further, so that every time width is equal to height of the image view.
As if don't scale properly it will get out of shape, and i need it to be in 1:1 ratio of width and height.
Will
Imageview:scale="fitxy"
work in this case ?
Please help thnk you.
I am working on android ICS
To keep aspect ratio, you should make the image the src rather than background.
Take a look at the ScaleType documentation here http://developer.android.com/reference/android/widget/ImageView.ScaleType.html.
You should try using either android:scaleType="centerInside" or android:scaleType="centerCrop".
Hope that helps!
android:scaleType="fitXY"
Fits the screen size of the device.
Try this adding this
android:layout_height="150dp" //or your designed proportion
android:layout_width="150dp" //or your designed proportion
android:scaleType="fitXY"
In my code I want to set a default image for my imageview. All my images are of 174px X 174px. So, I want the default image to be same size. This is my xml for image view
//....code
<ImageView
android:id="#+id/ivCover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="Default Image"
android:src="#drawable/default_cover" />
//....some other code
Now, my default_cover.jpg is also 174px X 174px. But it shows a smaller image. I've tried all
android:scaleType="centerInside"
android:scaleType="center"
android:scaleType="matrix"
even when most of them were senseless for me but still I tried all of 'em & none of them works. Then I specified the height & width of image by specifying
android:layout_width="174px"
android:layout_height="174px"
(I know using dp is better than px but because this image size is fixed & I was just testing it). So it shows
[default image]
while when loaded from an external url using
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url_source_for_image).getContent());
ivCover.setImageBitmap(bitmap);
desired image
[]
The two pictures may not look very different here but the difference is very clear on my android device. And please don't say that I didn't try other solutions..
Here is a list of links of so itself..
ImageView fit without stretching the image
Fit image into ImageView, keep aspect ratio and then resize ImageView to image dimensions?
ImageView one dimension to fit free space and second evaluate to keep aspect ration
Resizing ImageView to fit to aspect ratio
Maximum width and height for ImageView in Android
Image in ImageView is stretched - Android
Android: How to prevent image from being scaled in ImageView or ImageButton?
Sounds like the answer is to use drawable-nodpi. For future reference, if you have the same named image in both the ldpi/hdpi/etc and in no-dpi, I think the no-dpi one will be ignored.
I am building an android application with eclipse and I'm struggling to master the image positioning in the screen. I have put an image in a relative layout, and I want the borders of the image to match perfectly the borders of the screen, but when I extend the image manually it never fits and even if I put padding :/
(see the right side is ok, but not the left, the problem is not even a problem about the dimensions of the screen)
Thank you for your help
If you want to do that, you need to take the dimensions of the screen using this code :
// pixels
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Then you need to set programmatically the dimensions of the picture using the width and height properties.
If you need that your image to be the backgroung of the activity you can use the background property.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootRL"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
</RelativeLayout>
The "#drawable/your_image_name" is your image. The image should be the dimensions that google recomends for deferent sizes of screen.
I am developing application having a resemblance appearance like " Gallery application".
When I click on image from the gallery... I want to fit image to whole screen..
I used this code..but it does not work .
can you guide me for this ...
Here is code for the same:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
imgView.setMinimumWidth(width);
imgView.setMinimumHeight(height);
imgView.setMaxWidth(width);
imgView.setMaxHeight(height);
you should use the following attribute of the imageview to fit the image to the screen.
Controls how the image should be resized or moved to match the size of this ImageView.
Must be one of the following constant values.
Constant Value
matrix 0
fitXY 1
fitStart 2
fitCenter 3
fitEnd 4
center 5
centerCrop 6
centerInside 7
android:scaleType="fitxy"
like wise you can use others to change the size of your image.
You may consider having the image open in its own activity, with android:noHistory="true" in the manifest, and onClick() have it end the activity. That way you don't have to worry about the image resizing and ruining everything in the activity it is being chosen in.
New to Android, bad with layouts so this is probably a simple solution but I can't find it. I am adding an image to a ListView, the ListView is defined like this:
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
Image is added like this:
ImageView image = new ImageView(context);
image.setScaleType(ImageView.ScaleType.FIT_CENTER);
image.setAdjustViewBounds(true);
image.setImageDrawable(drawable);
return image;
in the ListAdapter. I want the Image to scale so the width fills the screen and the height adjust proportionally. What is happening is the image is scaling down so the height fills the list row but there is plenty of room for the width to be bigger. I had this working earlier but can't figure out what changed. Why is the image shrinking to some seemingly arbitrary height and how do I get it to fill the screen by width?
Edit:
So this happened when I started building for 1.6 instead of 1.5, probably a resolution thing. I guess the image is a bit sharper when it's small but I want it larger, it's almost unusable smaller and I am not able to get a larger image, it's from the web.
I think there is no really "simple" solution, but it's already answered here (without list's, but i don't think it matters):
Android: How to stretch an image to the screen width while maintaining aspect ratio?
Have you tried ImageView.ScaleType.FIT_XY ?
Scale Types