I have horizontal scroll view in which i have to add images which are coming from server which are shown of equal size in height and width.
how to set height and width with centre zooming of image
You can use this DynamicHeightImageView. You have to explicitly give the with of the imageview here and height will be set by setHeightRatio() method. You can use scaleType as centerCrop on imageView or if you want to use the zooming you can use any zooming animation.
Related
I have a SimpleDraweeView (from Fresco) like Imageview in my android app. Its dimensions are match_parent for both height and width. I want to create a separate view which will be showing the bottom 54dp of content of the SimpleDraweeView .
The new view will have width as screen width (match_parent) and height as 54dp .
How can i extract the bottom 54dp height of the SimpleDraweeView and whatever image portion comes in that , create a separate view which will show that 54dp height content.
So there should be method which takes SimpleDraweeView as param and should output View/ImageView with the required image content.
Use ConstraintLayout, and set the view2's layout as:
constraint_bottom_tobottomof=#+id/view1
and height is 54dp, then it occupies the bottom 54dp of view1.
I've an app that display list of images along with some text in a listview.
It actually fetches those images through web service.
If i use wrap_content for ImageView, it may stretch and the list will be irregular if the image size varies.
If i hardcode by giving some width and height (in dp), does it affects our multi screen support concept?
I wouldn't advise you to use wrap_content for the ImageView.
You could try setting a fixed height to it and use it full-width.
For the fixed size you have to use dp(Density Independent Pixels) which will result in having the size of this view 'almost' the same on any device. An by almost I mean you won't have the exact same percentage on the screen(for obvious reasons) but Android will scale it appropriately.
Second and most important is to set the scale_type property to the ImageView component in the xml file. There are various options but probably center_crop would fit your needs the best(I advise you to try out all the rest of them too, so you can understand the difference between, center, centerCrop, centerInside, fitCenter, fitEnd, fitStart, fitXY, matrix - these are all the possible values scale_type can have).
EDIT:
Here is the documentation description for these types:
center Displays the image centered in the view with no scaling.
centerCrop Scales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view.
centerInside Scales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center.
fitCenter Scales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view.
fitStart Same as fitCenter but aligned to the top left of the view.
fitEnd Same as fitCenter but aligned to the bottom right of the view.
fitXY Scales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio.
If You want to display it in a ListView then it is better to hard-code the dimension. and add ScaleType you want to the image.
If you want to use GridView then use this property
android:stretchMode="columnWidth"
android:numColumns="auto_fit"
the columns are adjusted dynamically according to the density of the screen when using auto_fit
I'm working on mdpi, and when I add a imageView to the activity it doesnt fill the screen, I tried setting the scaleType to fitXY but the image didnt fill the screen, also I'm using a relativeLayout
You must set width and height parameters as match_parent in your XML layout (instead of wrap_content)
I have 4 views in the same activity. I want to move each Imageview on touch in whole screen, but it allow me to move in its width height.
Each image view's layout height and width is wrap_content.
It works fine with one image view with fill_parent.
Its explained in this example.
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.