Instead of creating a new one ImageView, getViewyou should convert convertViewto the desired view. Here is an example of one way to do this:
public View getView(int position, View cv, ViewGroup parent) {
if (! convertView istanceof ImageView)
{
ImageView cv = new ImageView(mContext);
cv.setLayoutParams(new Gallery.LayoutParams(150, 100));
cv.setScaleType(ImageView.ScaleType.FIT_XY);
cv.setBackgroundResource(mGalleryItemBackground);
}
cv.setImageResource(mImageIds[position]);
return cv;
}
Just convert the convertView to whatever you want, but first make sure it has the correct look.
. . , 500x500 , res/drawable, 125x125 . , , . , ,
int maxSize = 125;
int resId;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeResource(c.getResources(), resId, opts);
int w = opts.outHeight, h = opts.outHeight;
int maxDim = (w>h)?w:h;
, , , . 500x500, 125x125, 1 4 , int inSample = 500/125;
int inSample = maxDim/maxSize;
opts = new BitmapFactory.Options();
opts.inSampleSize = inSample;
, .
Bitmap b = BitmapFactory.decodeResource(c.getResources(), resId, opts);
, . opts.inSampleSize 1, 500x500.