Q:

Blank image in Gallery view – Android

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:

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?

A:

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);

}

