<pre name="code" class="java">/* * 完成对左右划屏 */ @Override public 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; }
Android中Activity中左右滑动手势的监听
时间: 2024-10-05 09:43:02