私はAndroidアプリを作成していますが、フリングで切り替えることができるいくつかのレイアウトを提供したいと思います(Androidのホーム画面など)。このコードを使用して、切り替え用のレイアウトを取得しました。
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE) {
//vFlipper is a ViewFlipper, but it is not important for me to have it. As long as I can display several layouts and switch them by thumb touch, in a way that the layout will follow the thumb, that's fine.
if (vFlipper.getDisplayedChild() == 0)
return false;
vFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in));
vFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out));
vFlipper.showPrevious();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE) {
if (vFlipper.getDisplayedChild() == vFlipper.getChildCount() - 1)
return false;
vFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_in));
vFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out));
vFlipper.showNext();
}
return true;
}
しかし、これはホーム画面のようには機能しません。ホーム画面では、画面を横に引いて移動するのを確認できます。フリングを完了して画面を切り替える必要はありません。画面が親指で動きます。私のコードは完全なフリングジェスチャをチェックしてから、スイッチングとアニメーションを起動します。これで、完全なソリューションではおそらくGestureDetectorとonFlingメソッドが削除され、onMoveイベントが使用されることがわかりましたが、それを実装する方法とonMoveメソッドに何を入れるかがわかりません。これ、ビデオ、または書面による明確なデモンストレーションをご存知の場合は、リンクをいただければ幸いです。そのようなデモンストレーションを書くことを気にしないのであれば、それもありがたいです。