scrollviewとカスタムコントロールの上下スライド衝突iphone時間コントロールwheelviewを模倣
13304 ワード
/**
* ViewPager ScrollView
* @Description: ViewPager ScrollView
*/
public
class
ScrollViewExtend
extends
ScrollView {
//
private
float
xDistance, yDistance, xLast, yLast;
public
ScrollViewExtend(Context context, AttributeSet attrs) {
super
(context, attrs);
}
@Override
public
boolean
onInterceptTouchEvent(MotionEvent ev) {
switch
(ev.getAction()) {
case
MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
xLast = ev.getX();
yLast = ev.getY();
break
;
case
MotionEvent.ACTION_MOVE:
final
float
curX = ev.getX();
final
float
curY = ev.getY();
xDistance += Math.abs(curX - xLast);
yDistance += Math.abs(curY - yLast);
xLast = curX;
yLast = curY;
if
(xDistance > yDistance){
return
false
;
}
}
return
super
.onInterceptTouchEvent(ev);
}
}
, , 。
だからここでACTIOM_MOVEで する、XY の を することができ、
コードは のとおりです./**
* ViewPager ScrollView
* @Description: ViewPager ScrollView
*/
public class ScrollViewExtend extends ScrollView {
//
private float xDistance, yDistance, xLast, yLast;
public ScrollViewExtend(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
xLast = ev.getX();
yLast = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - xLast);
yDistance += Math.abs(curY - yLast);
xLast = curX;
yLast = curY;
// X Y 1.5 true scrollview
if(xDistance> yDistance*1.5){
return true;
}else{
return false;
}
}
return super.onInterceptTouchEvent(ev);
}
}