Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中循环画布_Android_Loops_Touch Event_Ontouchlistener - Fatal编程技术网

在Android中循环画布

在Android中循环画布,android,loops,touch-event,ontouchlistener,Android,Loops,Touch Event,Ontouchlistener,有人知道如何循环绘制画布吗?我想稍后添加一个onTouch方法并获得X位置。多谢各位 @Override protected void onDraw(Canvas canvas) { //Canvas canvas= new Canvas(); xp1 = canvas.getWidth()/2; Log.d("test1", "It went pass onDraw"); xp2 = canvas.getWidth()/2; yp1 = 25;

有人知道如何循环绘制画布吗?我想稍后添加一个onTouch方法并获得X位置。多谢各位

  @Override
protected void onDraw(Canvas canvas) {
    //Canvas canvas= new Canvas();
    xp1 = canvas.getWidth()/2;
    Log.d("test1", "It went pass onDraw");
    xp2 = canvas.getWidth()/2;
    yp1 = 25;
    yp2 = 760;
    canvas.drawColor(Color.BLACK);
    canvas.drawBitmap(paddle1, xp1,yp1, null);
    canvas.drawBitmap(paddle2,xp2,yp2, null);
    Paint white = new Paint();
    white.setColor(Color.WHITE);
    canvas.drawText("Score P1:"+ p1Score +" P2: " + p2Score , 700, 20,white );  
    Log.d("test1", "It's done with onDraw");

}
调用方法

invalidate();
每当您想回调
'onDraw'
方法时

aSampleCode(){
        image.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                switch(event.getAction())
                {
                case MotionEvent.ACTION_MOVE:

                    x= event.getRawX()

                    break;
                case MotionEvent.ACTION_UP:
                                    invalidate();
                    break;
                case MotionEvent.ACTION_DOWN:
                    break;

                default:
                    break;
                }
                return true;
            }
        });
    }
}

循环画布意味着什么?比如继续画画布