如何从AppWidget-Layout中的ImageView覆盖onDraw()方法?

时间:2012-11-01 09:34:42

标签: android android-widget android-appwidget ondraw

在activity-context中,通过创建扩展到View或在本例中为ImageView的自定义类,可以轻松覆盖onDraw()方法。使用LayoutInflater或它的实例也可以轻松访问该视图。

现在我正在开发一个AppWidget,但是使用了RemoteViews。

任何想法是怎么做到的?


确定。看来我在stackoverflow中找到了一个解决方案:

“只需​​创建一个位图,用它创建一个Canvas,然后绘制它 使用你的onDraw代码。然后创建一个ImageView(即 允许在小部件中)并将它显示的图像设置到你的位图。“ (Dynamically adding a View to an android widget

通过位图创建画布: (creating an empty bitmap and drawing though canvas in android

Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap bmp = Bitmap.createBitmap( 150, 150, conf ); // this creates a MUTABLE bitmap
Canvas cv = new Canvas( bmp );
//cv.draw...

绘图后我只需要将该位图推送到remoteViews。

希望它对你有帮助!

=)

0 个答案:

没有答案