我想在我的 appwidget 中使用多个 CustomView,因此想从每个 CustomView 创建一个位图。 所以我尝试了
Bitmap customBitmap = customView.getDrawingCache(true);
remoteViews.setImageViewBitmap(R.id.imageView1, customBitmap );
但它根本不起作用。
有什么建议吗?
最佳答案
yes, it is drawn on a canvas
我会做这样的事情:
public Bitmap createCustomView(){
Bitmap bitmap = Bitmap.createBitmap(BITMAP_WIDTH, BITMAP_HEIGHT, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
// draw on the canvas:
// ...
return bitmap;
}
然后将Bitmap
设置为ImageView
:
remoteViews.setImageViewBitmap(R.id.imageView1, createCustomView() );
关于android - 使用自定义 View 创建小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17901746/