我想要在我的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);
}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
[...]
}
}谢谢你的时间,马尔蒂塔
发布于 2013-07-17 05:44:31
您应该在表面视图中使用onTouchEvent。
https://stackoverflow.com/questions/16021688
复制相似问题