android-表面视图:"Object is disappearing"

android-SurfaceView: "Object is disappearing"

哎呀。我在使用 android surfaceView 时遇到问题。我正在尝试通过更改球的 x、y 坐标来制作球的动画。但是球正在消失......请查看代码并确定问题所在, 问候。`

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);
    canvas.drawBitmap(tile1, axisX, axisY,null);        //LINE ONE objects
    canvas.drawBitmap(tile2, axisX+78, axisY,null);
    canvas.drawBitmap(tile3, axisX+156, axisY,null);
    canvas.drawBitmap(tile4, axisX+234, axisY,null);


    canvas.drawBitmap(movingStick, (mWidth-movingStick.getWidth())/2, mHeight-200,null);
    canvas.drawBitmap(mBall, balCurrPosX,balCurrPosY  ,null);

}

//线程代码

Thread t=new Thread(new Runnable() {

    private boolean moveUp = true;


    @Override
    public void run() {
        // TODO Auto-generated method stub
        try{

            while (true) {
            if (balCurrPosY >= mHeight){
                moveUp= false;
            }else if(balCurrPosX<=0){
                moveUp = true;
            }
            if(moveUp)
                balCurrPosY--;
            else
                balCurrPosY++;
            Thread.sleep(2000);
            postInvalidate();
            }


        } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
    }
});`

您忘记在代码末尾启动新线程:

     } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
    }
}).start();