I have one question. I want to set one image to image button. I have one button image of size 90 x 48. I want to set this image on Image button.
Problems:
I need to set image on background parameter or src parameter?
If i set image on background parameter its not showing its actual size(smaller than actual size) if i have set the Layout width = wrap content and Layout Height= wrap content. If i give Layout width = 98dip and Layout Height= 48dip then its showing the same size. Is it a coorect way?
thanks
set image as background Parameter sometimes src makes problem
if you are set width and height as wrap_content then android will check the screen size and try to adjust to your screen if screen size is big then android displays your image as its actual height and width and if screen size is less then it will compress your image
so best way is to set height and width is as wrap_content if you have to use portrait and landscape mode both
Yes.
If you use Layout width = wrap content and Layout Height= wrap content, image will be as actual size. Maybe just the density of your monitor is less than the density of your phone?
Remember dip != pixels.
Related
I need an ImageView in which the user of my app loads an image from his gallery or camera. If the image is landscape, the ImageView width should be equal to screen width. If the image is portrait, the ImageView should take up as much screen space as there is available (I have a view above and a view below the ImageView). How can I achieve this?
Below is the desired result:
First you have to obtain the photo orientation, this can be achieved by reading its EXIF data. The answers to this question can help you to read the EXIF data. Then you have to change the width and height of your ImageView. If the image is portrait then you can use "match_parent" to both height and width. If the image is in landscape then put the height with "wrap_content" and the width in "match_parent". You need to do this by code.
I have an application which the user can capture images and then send them
to the server. I set the image to be as Base64 and then send it to the server.
In the application I have this screens:
Feed
Post Screen
Fullscreen Image (Landscape)
When the user enters to each screen I get from the server a Base64 and
decode it to bitmap and set it to be the source of the imageview.
each screen has it's layout.
for the feed and post screens I set the imageview width and height to be hardcoded with some dp, and for the fullscreen image I set them to be fill_parent.
Now for each imageview I set the scale type to : fitXY, but I see that the
pictures are streched and in the fullscreen mode I can see the pixels.
I want to set the image to fit the xy but to be smooth as possible
I tried to set the adjustToBound to true and scaleType to cropCenter, fitCenter
and etc but it doesn't help.. how can I save the aspect ratio?
In order for adjustViewBounds to work, one dimension of the ImageView needs to be set to a hard value like dp value or match_parent, and the other dimension needs to be set to wrap_content. adjustViewBounds will make the wrap_content dimension adjust to be the right size to keep the image's aspect ratio.
Thanks to this site, I successfully implemented a Horizontal ListView of ImageViews.
Now what I need is for the ImageViews in the list to have a fixed height (they're part of a more complex layout, so I'm using the LinearLayout weight trick to give it a height equal to 1/3 of the screen height), and a width that adjusts in relation to the height without destroying aspect ratio. The images have a longer height than width - an aspect ratio similar to a phone on portrait.
Now I've tried setting the scaleType to the different available settings, also set adjustViewBounds to true, and set the layout_width to wrap_content and layout_height to fill_parent. The nearest I got to doing it was this:
http://img849.imageshack.us/img849/1289/device20120831133004.png
(i placed the white borders as image background)
What else can be done?
Problem here is that your ImageView cannot be adjusted to desired height because it's aspect ratio is different from screen. Your view matching screen height (or 1/3 of it) and width cannot be scaled proportionally without crop.
Try to set scaleType to centerCrop and load images resized to desired height.
I have an image which is actually 393 x 21 px, which I would like to set on the bottom of my View.
The problem is that, even if i set the width and the height to fill_parent, my image stays very small in the middle of the screen bottom and on the left and the right I have an empty field.
I can resolve this by reducing the Image width size mannualy but is ther any other solution whic could set the image in fullscreen ?
Thank you.
//in your xml Image attribute as
android:scaleType="fitXY"
or //using thru programatically
imgview.setScaleType(ScaleType.FIT_XY);
I need something like<img width="100%" /> for Android <ImageView>. I mean resize width to all available space (shrink or enlarge width of image) and automatically change height to keep aspect ratio.
Something like <ImageView android:layout_width="match_parent" android:layout_height="auto">
Useandroid:scaleType="fitCenter"do with image what I want, but only with image, doesn't change height of View itself. When I set booth dimensions to match_parent I will get what I want, but only if I have only one image on the screen. But I need some texts under image.
It's only way create child of ImageView?
For exampleandroid:adjustViewBounds="true"does't do anything for me.
I found where is problem. Default implementation of ImageView can't enlarge image. If image is bigger than screen width android:adjustViewBounds="true" works correctly and adjust height to keep aspect ratio of image. But if image is smaller that screen width it don't upscale it.
This is cause by this code
if (newHeight <= heightSize) {
heightSize = newHeight;
}
in ImageView class (on line 688, API 10)
I made special child of ImageView which allow enlarge image to fit width.
Here is: https://gist.github.com/tprochazka/5486822