I am creating a appwidget that consists of a single custom view called Foo.
xml/widget.xml:
Another way to do this without using getDrawingCache()
:
MyView myView = new MyView(this);
myView.measure(500, 500);
myView.layout(0, 0, 500, 500);
Bitmap bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
myView.draw(new Canvas(bitmap));
remoteViews.setImageViewBitmap(R.id.imageView, bitmap);
I used cache not to redraw all the view so I couldn't use the code above. And I find it more elegant. I hope it could be useful to someone.