我试过了 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不为空
看看你的图片是不是太大了,另外,bitmap要转一下,bitmap = Bitmap.createBitmap(bitmap);