Unable To View Images Properly In A Gridview
MainActivity: public class AndroidCustomGalleryActivity extends Activity { private int count; private Bitmap[] thumbnails; private boolean[] thumbnailsselection; pr
Solution 1:
Instead of using a seperate imageview in your inflator what you have to do is remove imageview from inflator and set your thnumbnail as a background for your inflator relativewlayout.
Solution 2:
I think so your problem is when ur are getting the view of grid view there is mistake.
Error
publicObjectgetItem(int position) {
return position;
}
Correction
public Object getItem(int position) {
return f.get(position);
}
The error is because whenever you display image, you allocate the image size in Virtual memory. This can be overridden by resizing the bitmap and reducing the size and then display the image.
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
intwidth= bm.getWidth();
intheight= bm.getHeight();
floatscaleWidth= ((float) newWidth) / width;
floatscaleHeight= ((float) newHeight) / height;
// CREATE A MATRIX FOR THE MANIPULATIONMatrixmatrix=newMatrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// "RECREATE" THE NEW BITMAPBitmapresizedBitmap= Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
}
In your Code
Bitmap myresizedbitmap= getResizedBitmap(myBitmap,300, 300);
holder.imageview.setImageBitmap(myresizedbitmap);
Post a Comment for "Unable To View Images Properly In A Gridview"