I will try to be as clear as possible.
Here i'm trying to do
An image viewer in which the image will be displayed as strongly as on the deviceโs screen. For this you need and for a better user experience, I thought about the Gallery. Until everything is all right!
Problem
The problem is that only the Gallery.LayoutParams of the first image that I have in my gallery is used in the getView function of my adapter. This means that if the first image is a landscape and the second is a portrait, the second will be displayed as a landscape, with the same size as the first. I am resetting Gallery.LayoutParams, but it doesnโt matter, it still has LayoutParams of the first ImageView.
The code
public View getView(int position, View convertView, ViewGroup parent) { ImageView im = new ImageView(mContext); Bitmap bm = BitmapFactory.decodeByteArray(gallery.get(position).mContent, 0, gallery.get(position).mContent.length); im.setImageBitmap(bm); int width = 0; int height = 0; if (bm.getHeight() < bm.getWidth()) { width = getWindowManager().getDefaultDisplay().getWidth(); height = bm.getHeight() * width / bm.getWidth(); } else { height = getWindowManager().getDefaultDisplay().getHeight(); width = bm.getWidth() * height/ bm.getHeight(); } Gallery.LayoutParams lp = new Gallery.LayoutParams(width, height); im.setLayoutParams(lp); return im; }
If any of you understand why I will really know the answer,
android layout imageview gallery
Spredzy
source share