Skip to content

Commit 95806a5

Browse files
Merge pull request huanghaibin-dev#528 from codingbooo/master
Update CalendarLayout.java
2 parents 8fb4654 + 1f87b84 commit 95806a5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

calendarview/src/main/java/com/haibin/calendarview/CalendarLayout.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public class CalendarLayout extends LinearLayout {
147147

148148
private float downY;
149149
private float mLastY;
150+
private float mLastX;
150151
private boolean isAnimating = false;
151152

152153
/**
@@ -296,7 +297,7 @@ public boolean onTouchEvent(MotionEvent event) {
296297
mCalendarShowMode == CALENDAR_SHOW_MODE_ONLY_WEEK_VIEW) {//禁用手势,或者只显示某种视图
297298
return false;
298299
}
299-
if(mDelegate == null){
300+
if (mDelegate == null) {
300301
return false;
301302
}
302303
if (mDelegate.isShowYearSelectedLayout) {
@@ -318,10 +319,10 @@ public boolean onTouchEvent(MotionEvent event) {
318319
return true;
319320
case MotionEvent.ACTION_POINTER_DOWN: {
320321
final int indexx = event.getActionIndex();
321-
mActivePointerId = event.getPointerId( indexx);
322+
mActivePointerId = event.getPointerId(indexx);
322323
if (mActivePointerId == 0) {
323324
//核心代码:就是让下面的 dy = y- mLastY == 0,避免抖动
324-
mLastY = event.getY( mActivePointerId);
325+
mLastY = event.getY(mActivePointerId);
325326
}
326327
break;
327328
}
@@ -473,14 +474,17 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
473474
}
474475
final int action = ev.getAction();
475476
float y = ev.getY();
477+
float x = ev.getX();
476478
switch (action) {
477479
case MotionEvent.ACTION_DOWN:
478480
int index = ev.getActionIndex();
479481
mActivePointerId = ev.getPointerId(index);
480482
mLastY = downY = y;
483+
mLastX = x;
481484
break;
482485
case MotionEvent.ACTION_MOVE:
483486
float dy = y - mLastY;
487+
float dx = x - mLastX;
484488
/*
485489
如果向上滚动,且ViewPager已经收缩,不拦截事件
486490
*/
@@ -503,7 +507,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
503507
return false;
504508
}
505509

506-
if (Math.abs(dy) > mTouchSlop) {//大于mTouchSlop开始拦截事件,ContentView和ViewPager得到CANCEL事件
510+
if (Math.abs(dy) > Math.abs(dx) ) { //纵向滑动距离大于横向滑动距离,拦截滑动事件
507511
if ((dy > 0 && mContentView.getTranslationY() <= 0)
508512
|| (dy < 0 && mContentView.getTranslationY() >= -mContentViewTranslateY)) {
509513
mLastY = y;
@@ -839,7 +843,7 @@ private void hideWeek(boolean isNotify) {
839843
*/
840844
private void showWeek() {
841845
onShowWeekView();
842-
if(mWeekPager != null && mWeekPager.getAdapter()!= null){
846+
if (mWeekPager != null && mWeekPager.getAdapter() != null) {
843847
mWeekPager.getAdapter().notifyDataSetChanged();
844848
mWeekPager.setVisibility(VISIBLE);
845849
}

0 commit comments

Comments
 (0)