如何检测左/右和上/下之间的滑动方向

我的问题:如何检测用户向上/向下移动手指的时间与左/右相比(我如何知道他们的手指向哪个方向移动)?


我的情况:我想在他们上下移动手指时改变我的应用程序的亮度(向上=更亮,向下=更暗),我想根据他们的左/右滑动在活动和/或视图之间切换。


慕容708150
浏览 432回答 3
3回答

ABOUTYOU

我正在写这个答案,关于如何使用它Activity和Fragment许多人正在寻找它。public class MyActivity extends Activity implements View.OnTouchListener{     private RelativeLayout someLayout;     //take any layout on which you want your gesture listener;     @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);    gestureDetector=new GestureDetector(this,new OnSwipeListener(){        @Override        public boolean onSwipe(Direction direction) {            if (direction==Direction.up){               //do your stuff                Log.d(TAG, "onSwipe: up");            }            if (direction==Direction.down){               //do your stuff                Log.d(TAG, "onSwipe: down");            }            return true;        }    });    someLayout.setOnTouchListener(this);}    @Override    public boolean onTouch(View v, MotionEvent event) {      Log.d(TAG, "onTouch: ");      gestureDetector.onTouchEvent(event);      return true;  }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android