Android实现微信侧滑删除当前页面
本文实例为大家分享了微信侧滑删除当前页面的具体代码,供大家参考,具体内容如下
效果图不是太明显 实际上有finish动画
代码
package com.finddreams.slidingback.ui; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; /** * 手势滑动的Activity,只需要继承就可实现手势滑动 * Title: GestureBackActivity.java * @author Angus * 2016年11月16日 * @version 2.0 */ public class GestureBackActivity extends Activity { private GestureDetector myDectector; private static final String TAG = "GestureBackActivity"; boolean flingFinishEnabled = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initGestureDetector(); AppManager.getAppManager().addActivity(this); } private void initGestureDetector() { if (myDectector == null) { myDectector = new GestureDetector(this, new MyGestureListener()); } } @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (flingFinishEnabled) { return myDectector.onTouchEvent(ev) || super.dispatchTouchEvent(ev); } return super.dispatchTouchEvent(ev); } /** * 手势监听器 * */ public class MyGestureListener implements OnGestureListener { @Override public boolean onDown(MotionEvent e) { // Toast.makeText(getApplicationContext(),"down",Toast.LENGTH_SHORT).show(); return true; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent e) { // Toast.makeText(getApplicationContext(),"onSingleTapUp",Toast.LENGTH_SHORT).show(); return true; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // TODO Auto-generated method stub return false; } @Override public void onLongPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (e1.getX() - e2.getX() > 100 && Math.abs(velocityX) > 0) { Log.d(TAG, "向左滑动"); } else if (e2.getX() - e1.getX() > 100 && Math.abs(velocityX) > 0) { Log.d(TAG, "向右滑动"); AppManager.getAppManager().finishActivity(); } return false; } } }
demo 下载
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
赞 (0)