Android中Activity中左右滑动手势的监听

来源:互联网 发布:8月经济数据 编辑:程序博客网 时间:2024/05/17 00:00
<pre name="code" class="java">/* * 完成对左右划屏 */@Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:prev.set(event.getX(), event.getY());break;case MotionEvent.ACTION_UP:break;case MotionEvent.ACTION_MOVE:float moveX = prev.x - event.getX();// 左滑if (moveX > 150 && moveX < 5000) {// mDesignClothesBackground// .setBackgroundResource(idClothesBackground[0]);}// 右滑else if (moveX < -150 && moveX > -5000) {// mDesignClothesBackground// .setBackgroundResource(idClothesBackground[1]);}}return false;}


                                             
1 0