Yandex的MapView的内部滚动型不垂直滚动

问题描述 投票:0回答:2

的MapView只能侧身滚动,因为如果你尝试垂直滚动了滚动正在采取行动。我试过requestDisallowInterceptTouchEvent(真);但它并没有帮助。

PS。 Yandex的MapView类扩展的RelativeLayout

android dictionary scrollview android-mapview
2个回答
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如果你设置这个真可以滚动嵌套视图如果父滚动型滚动启用它是假的。

对于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;
        }
    });

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);
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.