MapView inside a ScrollView?

前端 未结 9 1223
时光取名叫无心
时光取名叫无心 2020-11-28 04:18

I would like to have a MapView inside a ScrollView, however when I try to scroll the map, the ScrollView takes priority! Is there a way to give the MapView priority when scr

相关标签:
9条回答
  • 2020-11-28 04:49

    You can simply put the MapView in a Layout itself and override onTouch or set an Click-Listener - easiest way for me since i needed a touch on the whole MapView in my ScrollView.

    0 讨论(0)
  • 2020-11-28 04:49

    If you have mapview in scroll view then you have to explicity mention the follwing paramets to the MapView:

    mMapView.setClickable(true);
    mMapView.setFocusable(true);
    mMapView.setDuplicateParentStateEnabled(false);
    
    0 讨论(0)
  • 2020-11-28 04:54

    I have had a same problem for 10 days, but I got a solution a few minutes ago!! Here is the solution. I made a custom MapView and override onTouchEvent() like this.

    @Override
    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;
    }
    
    0 讨论(0)
提交回复
热议问题