mapview仅向侧面滚动,就像您尝试垂直滚动ScrollView正在执行操作一样。我试过requestDisallowInterceptTouchEvent(true);但它没有帮助。
PS。 Yandex MapView扩展了RelativeLayout
答案 0 :(得分:1)
尝试使用MapView onTouchEvent,如下所示
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle MapView's touch events.
super.onTouchEvent(ev);
return true;
}
requestDisallowInterceptTouchEvent如果设置为true,则可以滚动嵌套视图,如果为false,则启用父ScrollView滚动。
对于ListView,我们不需要这个事件监听器listview.setNestedScrollingEnabled(true);
mapview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
super.onTouchEvent(ev);
return true;
}
});
答案 1 :(得分:0)
您必须创建自定义MapView。请按照下面提供的代码段进行操作
public class AppMapView extends MapView {
public AppMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_UP:
System.out.println("unlocked");
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
case MotionEvent.ACTION_DOWN:
System.out.println("locked");
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return super.dispatchTouchEvent(ev);
}
}