繁体   English   中英

图库视图中的空白图像– Android

[英]Blank image in Gallery view – Android

我知道图库视图已过时,但我仍然需要它。

我已经在Nexus 7,Samsung S4,LG手机上对其进行了测试,并且可以正常工作,但是在HTC手机上,我没有显示空白,而是在Gallery中找到了一些图片,例如:

在此处输入图片说明

这是代码示例:

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

ImageAdapter类扩展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;
    }
}

怎么了

我已经使用了这篇文章 ,现在对我有用。

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM