赞
踩
主要思路:activity实现OnTouchListener接口,继承方法,GestureDetector.SimpleOnGestureListener的一个对象,用来识别各种手势动作,源码中SimpleOnGestureListener实现的是OnGestureListener, OnDoubleTapListener这两个接口,如果你只是做检测左右滑动可以去只实现OnGestureListener,然后覆盖public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)方法。
- public class fgMeterActivity extends Activity implements View.OnTouchListener{
- private static final int FLING_MIN_DISTANCE = 50;
- private static final int FLING_MIN_VELOCITY = 0;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_meter);
-
- ButterKnife.bind(this);
-
- mGestureDetector = new GestureDetector(this, myGestureListener);
- ScrollView scrollView = findViewById(R.id.sc);//布局的主容器
- scrollView.setOnTouchListener(this);
- scrollView.setLongClickable(true);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。