解决ScrollView嵌套ViewPager出现的滑动冲突问题
2015-07-31 09:56
656 查看
/**
*
解决ScrollView嵌套ViewPager出现的滑动冲突问题
*/
public class ScrollView1 extends ScrollView {
private boolean canScroll;
private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;
public ScrollView1(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(new YScrollDetector());
canScroll = true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(ev.getAction() == MotionEvent.ACTION_UP)
canScroll = true;
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}
class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if(canScroll)
if (Math.abs(distanceY) >= Math.abs(distanceX))
canScroll = true;
else
canScroll = false;
return canScroll;
}
}
}
*
解决ScrollView嵌套ViewPager出现的滑动冲突问题
*/
public class ScrollView1 extends ScrollView {
private boolean canScroll;
private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;
public ScrollView1(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(new YScrollDetector());
canScroll = true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(ev.getAction() == MotionEvent.ACTION_UP)
canScroll = true;
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}
class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if(canScroll)
if (Math.abs(distanceY) >= Math.abs(distanceX))
canScroll = true;
else
canScroll = false;
return canScroll;
}
}
}
相关文章推荐
- C# Thread类的应用
- solrcloud 4.3 安装
- 前端Nginx,后端Apache获取用户真实IP地址
- 七月英语
- 谷歌字体连接超时解决方案
- 业务系统到底需要什么样的ID生成器
- ORACLE 日期加减操作
- heartbeat+DRBD+mysql+LVS集群实战
- Shell 学习8 - Shell 替换
- 后缀式与中缀式的恩怨-->中缀表达式转化为后缀表达式
- zoj 2770 Burn the Linked Camp 差分约束系统
- 深度优先搜索算法(DFS)
- 嵌入式linux之触摸屏驱动框架
- 一款DIY移动电源的性能
- zoj 2770 Burn the Linked Camp 差分约束系统
- EventHandler 与常见的.Net预定义委托
- 2021 发工资咯:)
- oracle中的add_months()函数总结
- oracle中的add_months()函数总结
- 小事例让你快速理解java观察者模式