我正在使用onFling
功能来刷卡ScrollView
。我面临的问题是,当我从上到下滑动/滚动时,它会将我的标签从一个向右/向左滑动到另一个。所以我需要当我滚动时我的向左/向右滑动功能不起作用。
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
final RelativeLayout detail = (RelativeLayout) findViewById(R.id.layout_detail);
final RelativeLayout photo = (RelativeLayout) findViewById(R.id.layout_detail_photo);
final RelativeLayout pod = (RelativeLayout) findViewById(R.id.layout_detail_pod);
final ToggleButton btn_detail = (ToggleButton) findViewById(R.id.btn_detail);
final ToggleButton btn_pod = (ToggleButton) findViewById(R.id.btn_pod);
final ToggleButton btn_photo = (ToggleButton) findViewById(R.id.btn_photo);
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
if ((detail.getVisibility() == View.VISIBLE)
&& (pod.getVisibility() == View.GONE)
&& (photo.getVisibility() == View.GONE)) {
detail.setVisibility(View.GONE);
photo.setVisibility(View.GONE);
pod.setVisibility(View.VISIBLE);
btn_photo.setSelected(false);
btn_pod.setSelected(true);
btn_detail.setSelected(false);
} else if ((detail.getVisibility() == View.GONE)
&& (pod.getVisibility() == View.VISIBLE)
&& (photo.getVisibility() == View.GONE)) {
detail.setVisibility(View.GONE);
photo.setVisibility(View.VISIBLE);
pod.setVisibility(View.GONE);
btn_photo.setSelected(true);
btn_pod.setSelected(false);
btn_detail.setSelected(false);
} else if ((detail.getVisibility() == View.GONE)
&& (pod.getVisibility() == View.GONE)
&& (photo.getVisibility() == View.VISIBLE)) {
detail.setVisibility(View.VISIBLE);
photo.setVisibility(View.GONE);
pod.setVisibility(View.GONE);
btn_photo.setSelected(false);
btn_pod.setSelected(false);
btn_detail.setSelected(true);
}
}
// left to right swipe
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
if ((detail.getVisibility() == View.VISIBLE)
&& (pod.getVisibility() == View.GONE)
&& (photo.getVisibility() == View.GONE)) {
detail.setVisibility(View.GONE);
photo.setVisibility(View.VISIBLE);
pod.setVisibility(View.GONE);
btn_photo.setSelected(true);
btn_pod.setSelected(false);
btn_detail.setSelected(false);
} else if ((detail.getVisibility() == View.GONE)
&& (pod.getVisibility() == View.GONE)
&& (photo.getVisibility() == View.VISIBLE)) {
detail.setVisibility(View.GONE);
photo.setVisibility(View.GONE);
pod.setVisibility(View.VISIBLE);
btn_photo.setSelected(false);
btn_pod.setSelected(true);
btn_detail.setSelected(false);
} else if ((detail.getVisibility() == View.GONE)
&& (pod.getVisibility() == View.VISIBLE)
&& (photo.getVisibility() == View.GONE)) {
detail.setVisibility(View.VISIBLE);
photo.setVisibility(View.GONE);
pod.setVisibility(View.GONE);
btn_photo.setSelected(false);
btn_pod.setSelected(false);
btn_detail.setSelected(true);
}
}
return true;
}