我需要在SwipeRefreshLayout中放置谷歌地图视图,问题是SwipeRefreshLayout会在触摸事件上覆盖谷歌地图。当我尝试向上滚动地图时,SwipeRefreshLayout事件将被触发。当我滚动谷歌地图时,如何禁用SwipeRefreshLayout事件?
答案 0 :(得分:0)
我在Shiba J.提出的this线程中找到了解决这个问题的方法。我扩展了SwipeRefreshLayout并覆盖onInterceptTouchEvent。
public class OverviewSwipeRefreshLayout extends SwipeRefreshLayout {
public OverviewSwipeRefreshLayout(Context context) {
super(context);
}
public OverviewSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_MOVE:
return false;
case MotionEvent.ACTION_CANCEL:
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_UP:
return false;
default:
break;
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
super.onTouchEvent(ev);
return true;
}
}