Android实现微信侧滑删除当前页面 Android实现微信侧滑删除当前页面
Angus-wsj 人气:0想了解Android实现微信侧滑删除当前页面的相关内容吗,Angus-wsj在本文为您仔细讲解Android实现微信侧滑删除当前页面的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android微信侧滑删除当前页面,Android微信侧滑删除,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 下载
加载全部内容