Gallery and full-screen ImageView, the problem with combining them

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,

+6
android layout imageview gallery
source share
1 answer

The gallery makes all children have the same size. In addition, you create a new View every time getView () is called, and this is a terrible idea. You should use convertView if it is not null. There is currently no feature in Gallery, so convertView is always null, but to benefit from it in a future version of Android, use convertView anyway. This is also a good practice that you should apply to every adapter you write.

+4
source share

All Articles