public void Pattern(Canvas canvas) {
int x = 0;
int y = 0;
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(1);
paint.setAntiAlias(true);
paint.setColor(Color.MAGENTA);
paint.setTextSize(22);
canvas.drawText("movement pattern", 75, 55, paint);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
canvas.drawCircle(359, 300 , 4, paint);
canvas.drawCircle(425, 300, 4, paint);
// canvas.drawCircle(248, , 4, paint);
canvas.drawCircle(248, 380, 4, paint);
canvas.drawCircle(50, 300, 4, paint);
//canvas.drawCircle(5421, 6499, 4, paint);
// draw a thick dashed line,
paint.setColor(Color.BLUE);
canvas.drawLine(359, 300 , 425, 300, paint);
canvas.drawLine(425, 300, 248, 380, paint);
//canvas.drawLine(400, 500 ,248, 380, paint);
canvas.drawLine(248, 380 , 50, 300, paint);
canvas.drawLine(50, 300, 359, 300, paint);
}
activity_main.xml:
<Button
android:id="@+id/BPV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/View"
android:layout_below="@+id/btnShowLocation"
android:layout_marginLeft="15dp"
android:onClick="Pattern"
android:text="Pattern" />
<View
android:id="@+id/PV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/BPV"
android:layout_below="@+id/TextView1" />
基本上,在主布局中,我有4个按钮和所有作品。但 BPV按钮除外。 我想在点击 BPV按钮时在 PV 显示模式(Canvas画布)。但点击它时App力关闭。
答案 0 :(得分:0)
Pattern
方法的方法签名不正确。
当在XML中使用android:onClick时,必须为public void Pattern(View view)
当您单击没有对视图画布进行绘画访问的按钮时,您需要找出另一种方法来实现您的目的。