我有包含游戏刽子手的应用程序。我针对他们的绘画责任创建了一个单独的活动。这是代码:
public class DrawWisielec extends View
{
Paint paint;
int choose;
public DrawWisielec(Context context,int choose)
{
super(context);
this.choose = choose;
}
protected void onDraw(Canvas canvas)
{
canvas.drawRGB(0,0,0);
Paint Circle = new Paint();
Paint paint = new Paint();
Circle.setARGB(255,255,255,255);
Circle.setStyle(Paint.Style.STROKE);
Circle.setStrokeWidth(5);
paint.setARGB(255, 255, 255, 255);
paint.setStrokeWidth(5);
switch(choose)
{
case 1:
{
canvas.drawLine(50, 400, 100, 300, paint);
break;
}
case 2:
{
canvas.drawLine(100, 300, 150, 400, paint);
break;
}
case 3: canvas.drawLine(100, 300, 100, 50, paint);
case 4:canvas.drawLine(100,50,300,50,paint);
case 5:canvas.drawLine(300,50,300,100,paint);
case 6:canvas.drawCircle(300, 150, 50, Circle);
case 7:canvas.drawLine(300, 200, 300, 250, paint);
case 8:canvas.drawLine(300, 250, 250, 200, paint);
case 9:canvas.drawLine(300, 250, 350, 200, paint);
case 10:canvas.drawLine(300, 250, 275, 330, paint);
case 11:canvas.drawLine(300, 250, 325, 330, paint);
}
invalidate();
}
如何在代码如下的另一个活动的绘图的各个阶段之间切换:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game_mode_wisielec);
DrawLayout = (LinearLayout)findViewById(R.id.WisielecDrawLayout);
DrawWisielec draw = new DrawWisielec(this, choose);
DrawLayout.addView(draw);