i have 2 imageview. first one for containing the image and the other one as the frame.
i already set image position to have the same position as the frame after loading the image.
i also already check the value and its the same.
but somehow the image position is not the same as the frame when i try changing picture with 2 different size (width x height).
ivProfilePicture.setX(ivFrame.getX());
ivProfilePicture.setY(ivFrame.getY());
by the way, i use custom imageview for the image container, i only custom the function onMeasure. there's no image repositioning.
Related
I have a recycler view where cells contain an ImageView. I'd like the cells to match_parent width (the screen width), but expand height wise as needed and keep aspect ratio (wrap_content). The problem is that Glide will resize the image to match the placeholder image or (when reusing a cell) match whichever the previous image size was. Is there a way I can tell Glide to get the native image size, every time? I don't want the image to resize, I want the imageview to resize.
I have a row layout with
image
title which gets inflated on a list view.
The problem is the image should be of size 80dp x 80dp where there is no guarantee as the image may be null in the DB. So I would like to know how we could check wether for the availability of the image in the db.If it is available then inflate the image aligned left with the size 80dp x 80dp in the row layout that is inflated for a list view. Elhe nse don't display the image. (Using Picasso to load images over the network)...
In picasso there is a method called error.Then if the url is wrong then the image in the error is loaded.You should only check if the image path is null by checking the string.
I have a layout where I have to take an ImageView, and position it somewhere relative to something in the background image. For instance, the ImageView would be of an item, and on the background image there would be a shelf, and I would need to position the ImageView such that the item looks like it is on the shelf. Another example would be of a frame in the background, and I would need to position the image so it looks like it is in the frame. This needs to account for scaling. I do not need it to work through rotation, as there are different layouts for portrait and landscape.
One way would be to associate the relative position of these items with the background images themselves. For instance, the height of the position of the top of the table is at x% of the total height of the image. Then, when it scales, it's now at x% of the current height.
So I have this task to create a horizontal scrolling array of image buttons that are basically photo avatars of users. These avatars aren't constrained by aspect ratio or size, and so I've been playing with ways to scale them and format them. I've gotten them scaling via the scaletype="fitCenter" and using static width and height. But what I really want them to do is to butt up against one another. Currently if an image is taller than it is high, you get the kind of letterboxing but on the sides vs. the top (blank areas). I've tried all the different scaling values, wrapping each imagemap within a linearlayout, etc., but nothing I try seems to get rid of those (while displaying the entire image to scale). Is there any way to do this?
Just to reiterate what I think you're doing, you have three image scenarios:
Square image
Landscape image (wider than tall)
Portrait image (taller than wide)
Laying out a row of fixed-size ImageViews (or ImageButtons) using FIT_CENTER works great for what you need if all the images were either square or landscape, because the scaling will always make the image stretch to the horizontal bounds of the view (the largest dimension). However, with portrait images, the scaling causes the view to be inside the bounds of your fixed-size view so that the entire image height can be visible.
If you need to maintain the aspect ratio of the image, there really is no ScaleType to help with this because the logic would be circular (fit the view to the image, while simultaneously fitting the image to the view). The solution is to adjust the size (specifically, the width) of each ImageView to match what the image will be scaled to. Here's a sample of a factory method you might use to generate the ImageView to fit the image you want to put inside it. You could also modify this slightly to reset parameters on an existing ImageView if you like:
private ImageView getImageViewForThumbnail(Bitmap thumbnail) {
float viewHeight = //Your chosen fixed view height
float scale = ((float)thumbnail.getHeight()) / viewHeight;
float viewWidth = thumbnail.getHeight() / scale;
ImageView view = new ImageView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams((int)viewWidth, (int)viewHeight);
view.setLayoutParams(params);
view.setScaleType(ScaleType.FIT_XY);
view.setImageBitmap(thumbnail);
return view;
}
You're basically just calculating what the aspect width of the ImageView should be to match the fixed height you've chosen for all of them.
HTH
Use the scaleType fitXY, it stretches the image to the layout params you assigned, if the image has less dimensions and also shrinks the image to the layout params you assigned, if the image is large. The key point is to mention the image layout params to the imageView , that is the width and height of the image.
I have a layout in which I resize an image by doing a transformation with prescale. After the scale the image has the right size, but the layout container around it cuts its size of. I want the layout container arround it to show to complete image.
I just tried invalidate on the image, the container as well as requestLayout(). Any ideas?
Thanks
How are you transforming the image? If you are setting a matrix on an ImageView, you need to tell the ImageView to adjust its bounds to the size of the content. If you are scaling the image by setting a transformation on the Canvas, you must change the dimensions of the View yourself.