Android AppWidget 不能显示图片 只显示背景

新手上路,请多包涵

我试过了 setImageViewUri和setImageBitmap 都不管用

第一种

File file = new File("path");
if (file.exists()) {
    views.setImageViewUri(R.id.imageView, Uri.fromFile(file));
}

第二种

Bitmap myBitmap=null;
File file = new File("path");
if (file.exists()) {
    if(myBitmap!=null){
        myBitmap.recycle();
    }

BitmapFactory.Options options = new BitmapFactory.Options();
long fileLength =file.length();
int scale = (int) (fileLength / 300000);
if (scale == 1)
    options.inSampleSize = 2;
else if (scale == 2 || scale == 3)
    options.inSampleSize = 4;
else if (scale >= 4)
    options.inSampleSize = 8;
else
    options = null;
myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
views.setImageViewBitmap(R.id.imageView,myBitmap);

最后更新

appWidgetManager.updateAppWidget(appWidgetId, views);

然而都是只显示 Imageview的 背景而不是图片,path是正确的,Bitmap不为空

阅读 4.1k
1 个回答

看看你的图片是不是太大了,另外,bitmap要转一下,bitmap = Bitmap.createBitmap(bitmap);

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题