Android开发ScrollView上下左右滑动事件冲突整理二(根据角度)
Android的ScrollView滑动获得角度实例:
package com.cm.android.pad.view.itemView; import android.content.Context; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; import android.view.View; import android.widget.ScrollView; public class TestScroll extends ScrollView { private GestureDetector mGestureDetector; private static double SCROLL_ANGLE = 90; public TestScroll(Context context, AttributeSet attrs) { super(context, attrs); mGestureDetector = new GestureDetector(new YScrollDetecotr()); setFadingEdgeLength(0); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev); } class YScrollDetecotr extends SimpleOnGestureListener { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // if(distanceY != 0 && distanceX != 0){ // // } // if(Math.abs(distanceY) >= Math.abs(distanceX)){ // System.out.println("distanceX = " + distanceX + " , distanceY = " // + distanceY); // return true; // } // return false; double angle = Math.atan2(Math.abs(distanceY), Math.abs(distanceX)); // System.out.println("angle-->" + (180 * angle) / Math.PI); if ((180 * angle) / Math.PI < 180) { return false; } return false; } } }
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28