Android: AppWidget with custom view not working

前端 未结 4 973
余生分开走
余生分开走 2020-11-29 02:43

I am creating a appwidget that consists of a single custom view called Foo.

xml/widget.xml:



        
4条回答
  •  有刺的猬
    2020-11-29 03:08

    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.

提交回复
热议问题