我是一个有windows背景的程序员,我是Java和android的新手,
我想创建一个显示图表的小部件(不是应用程序).
经过长时间的研究,我知道我可以用Canvas,imageviews和Bitmaps做到这一点.
我绘制的画布应该与小部件大小相同.
所以问题是:我如何知道小部件大小(或图像视图大小),以便我可以将它提供给该功能
Bitmap.createBitmap(width_xx,height_yy,Config.ARGB_8888);
代码片段:在计时器运行方法中:
@Override
public void run() {
Bitmap bitmap = Bitmap.createBitmap(??, ??, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
//create new paint
Paint p = new Paint();
p.setAntiAlias(true);
p.setStrokeWidth(1);
//draw circle
//here i can use the width and height to scale the circle
canvas.drawCircle(50, 50, 7, p);
remoteViews.setImageViewBitmap(R.id.imageView, bitmap);
Run Code Online (Sandbox Code Playgroud)