1

I know about gallery view is outdated, but i still need it.

I've tested it on Nexus 7, Samsung S4, LG phones and it works fine, but on HTC phone I got blank place instead some images in Gallery, like this:

enter image description here

Here is a sample of code:

<Gallery
            android:layout_marginTop="5dp"
            android:id="@+id/gallery1"
            android:layout_width="match_parent"
            android:layout_height="350dp" />

class ImageAdapter extends BaseAdapter {

    @Override
    public int getCount() {
        return images.size();
    }

    @Override
    public Object getItem(int arg0) {

        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup vg) {
        ImageView image = new ImageView(getApplicationContext());
        image.setImageResource(images.get(position));
        image.setPadding(20, 20, 20, 20);
        image.setLayoutParams(new Gallery.LayoutParams(550, 450));
        image.setScaleType(ImageView.ScaleType.FIT_XY);
        return image;
    }
}

what is wrong with it?

Anton Kashpor
  • 1,255
  • 2
  • 18
  • 34

1 Answers1

0

I have used the article and it works for me now.

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
    int reqWidth, int reqHeight) {

// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);

}

Anton Kashpor
  • 1,255
  • 2
  • 18
  • 34