0

我想在我的 surfaceView 中添加一个 OnTouchListener,但我不太明白。我尝试在 MainActivity 中添加 OnTouchListener

surfaceView.setOnClickListener(this);

没有结果。有什么建议么?

主要活动:

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.surface_view);      
    surfaceView= (AnimationSurface) findViewById(R.id.surfaceView);
}

表面视图

public class AnimationSurface extends SurfaceView implements Runnable {

SurfaceHolder Holder;
Thread Thread = null;
boolean isRunning = true;
float x=0;
float y=0;

public AnimationSurface(Context context, AttributeSet attrs) {
    // TODO Auto-generated constructor stub
    super(context);
    Holder = getHolder();
    Thread = new Thread(AnimationSurface.this);
    Thread.start();     
}


@Override
public void run() {
    // TODO Auto-generated method stub
    [...]

    }
}

谢谢你的时间,马尔蒂塔

4

1 回答 1

0

你应该在surfaceview中使用onTouchEvent

于 2013-07-16T21:44:31.460 回答