视图的区别是什么onTouchEvent
:
public class MyCustomView extends View {
// THIS :
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
}
及其onTouchListener
:
MyCustomView myView = (MyCustomView) findViewById(R.id.customview);
myView.setOnTouchListener(new View.OnTouchListener() {
@Override
public void onClick(View arg0) {
// do something
}
});
或者
public class MyCustomView extends View {
public MyCustomView(Context context, AttributeSet attrs) {
// THIS :
setOnTouchListener(new View.OnTouchListener() {
@Override
public void onClick(View arg0) {
// do something
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
}
如果这两个不同,
我们是否需要同时实现?
首先调用哪个?
如果我有一些滚动和缩放功能,我应该在内部实现它们onTouchEvent
还是onTouchListener
?