这篇文章给大家分享的是有关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; 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; } } }
感谢各位的阅读!关于“Android如何实现微信侧滑删除当前页面”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!