【问题标题】:Create widget with customview使用 customview 创建小部件
【发布时间】:2013-07-27 19:37:46
【问题描述】:

我想在我的 appwidget 中使用几个 CustomView,因此想从每个 CustomView 中创建一个位图。 所以我尝试了

Bitmap customBitmap = customView.getDrawingCache(true);

remoteViews.setImageViewBitmap(R.id.imageView1, customBitmap );

但它根本不起作用。

有什么建议吗?

【问题讨论】:

  • 您能提供更多信息吗?确切的代码?
  • 我现在包含了原始代码
  • 这个自定义视图是什么样子的?
  • 基本上是一条路径
  • @Johannes 所以一切都画在画布上?

标签: android bitmap widget custom-view


【解决方案1】:

是的,它是在画布上绘制的

我会这样做:

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() );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    • 2021-01-24
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多