-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
...va/com/ellen/tableview/supertableview/adapter/superadapter/TableHorizontalScrollView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.ellen.tableview.supertableview.adapter.superadapter; | ||
|
||
import android.content.Context; | ||
import android.os.Build; | ||
import android.support.annotation.RequiresApi; | ||
import android.util.AttributeSet; | ||
import android.view.MotionEvent; | ||
import android.widget.HorizontalScrollView; | ||
|
||
/** | ||
* 解决与viewpager的滑动冲突问题 | ||
* | ||
* @author: WEI | ||
* @date: 2018/6/25 | ||
*/ | ||
public class TableHorizontalScrollView extends HorizontalScrollView { | ||
private final static String TAG = "CusHorizontalScrollView"; | ||
|
||
public TableHorizontalScrollView(Context context) { | ||
super(context); | ||
} | ||
|
||
public TableHorizontalScrollView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public TableHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) | ||
public TableHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
} | ||
|
||
@Override | ||
public boolean onInterceptTouchEvent(MotionEvent ev) { | ||
return super.onInterceptTouchEvent(ev); | ||
} | ||
|
||
/** | ||
* 可以在此处理冲突 | ||
* @param ev | ||
* @return | ||
*/ | ||
@Override | ||
public boolean dispatchTouchEvent(MotionEvent ev) { | ||
// 还没滑到右边,请求父控件不要拦截我的事件,事件自己处理 true ;已经滑到右边,则事件交由父控件处理 false。 | ||
// getParent().requestDisallowInterceptTouchEvent(!isScrollToRight()); | ||
return super.dispatchTouchEvent(ev); | ||
} | ||
|
||
/** | ||
* 也可以在此处理冲突 | ||
* @param ev | ||
* @return | ||
*/ | ||
@Override | ||
public boolean onTouchEvent(MotionEvent ev) | ||
{ | ||
switch (ev.getAction()) { | ||
case MotionEvent.ACTION_DOWN: | ||
break; | ||
|
||
case MotionEvent.ACTION_MOVE: | ||
if (isScrollToLeft() || isScrollToRight()) | ||
{ | ||
// 把事件交给父控件处理,例如:viewpager滑动 | ||
getParent().requestDisallowInterceptTouchEvent(false); | ||
} | ||
break; | ||
|
||
case MotionEvent.ACTION_UP: | ||
case MotionEvent.ACTION_CANCEL: | ||
// 请求父控件可以拦截事件 | ||
getParent().requestDisallowInterceptTouchEvent(false); | ||
break; | ||
|
||
default: | ||
} | ||
return super.onTouchEvent(ev); | ||
} | ||
|
||
/** | ||
* 是否已经滑到了最右边 | ||
* | ||
* @return | ||
*/ | ||
private boolean isScrollToRight() { | ||
return getChildAt(getChildCount() - 1).getRight() == getScrollX() + getWidth(); | ||
} | ||
|
||
/** | ||
* 是否已经滑到了最左边 | ||
* @return | ||
*/ | ||
private boolean isScrollToLeft() { | ||
return getScrollX() == 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters