我有一個很多孩子的看法。我需要的是在Swipe或Fling動作上實施反應。問題在於,如果我刪除所有孩子,它纔會真正起作用,否則,主佈局頂部的子視圖會嘗試滑動。如何忽略覆蓋視圖並檢測onFling(onSwipe)?
我都嘗試加入onSwipeListener到主佈局並添加GestureListener整個活動用同樣的成功。
我現在的(非工作)解決方案是這樣的:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule);
main_layout = findViewById(R.id.schedule_main_view);
Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade);
main_layout.startAnimation(fadeInAnimation);
GestureDetector.SimpleOnGestureListener simpleOnGestureListener =
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent event) {
return true;
}
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
Log.d(null,"Fling");
int dx = (int) (event2.getX() - event1.getX());
// don't accept the fling if it's too short
// as it may conflict with a button push
if (Math.abs(dx) > 20
&& Math.abs(velocityX) > Math.abs(velocityY)) {
if (velocityX > 0) {
Log.d(DEBUG_TAG, "onFling: " + event1.toString() + event2.toString());
Log.d(DEBUG_TAG, "onFling To Right");
} else {
Log.d(DEBUG_TAG, "onFling: " + event1.toString() + event2.toString());
Log.d(DEBUG_TAG, "onFling To Left");
}
return true;
} else {
return false;
}
}
};
shift = getIntent().getIntExtra(WEEK_SHIFT, CURRENT_WEEK);
mDetector = new GestureDetectorCompat(this,simpleOnGestureListener);
unDimScreen();
setupWeek();
}
重複:如果該活動是在該州時,有在頂部沒有子視圖,它按預期工作。
所以,問題是:我能做些什麼使活動獲取手勢忽略覆看法?
攔截觸摸ViewGroup中的事件是我需要的。謝謝! –