How to handle Touch Events on a Fragment?
直接对根布局进行监听
View view = inflater.inflate(R.layout.fragment_test, container, false);
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_MOVE){
//do something
}
return true;
}
});
//here the rest of your code
return view;
打开百度搜索,翻来覆去就是一篇文章的复制,使用根Activity注册监听到Fragment。
https://www.jianshu.com/p/3b20bce9bdbc
网友评论