是否有一种简单的方法在画布上绘制矩形并将其显示在像TextView这样的活动中?通过将画布视为一个视图来绘制矩形
我极力把我的矩形像这样:
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.MAGENTA);
Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
Rect locationrect = new Rect(10, 10, 200, 100);
c.drawRect(locationrect, paint);
View locationpic = (View)findViewById(R.id.locationview);
locationpic.draw(c);
在我的xml:
<View
android:id="@+id/locationview"
android:layout_width="520dp"
android:layout_height="489dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="220dp" />
这显然是不工作(它不会崩溃,但不显示矩形)..任何帮助,将不胜感激! 谢谢!
您将不得不创建自定义视图扩展视图以在xml布局中使用它们 – playmaker420
我修改了我的帖子,你能检查吗? :) – Diletante