MapView inside a ScrollView?

前端 未结 9 1280
时光取名叫无心
时光取名叫无心 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:38

    You can create a custom MapView like this:

    public class CustomMapView extends MapView {
    
        private MapFragment.ControlLock mCallbackControl;
    
        public CustomMapView(Context context) {
            this(context, null);
        }
    
        public CustomMapView(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
        }
    
        public CustomMapView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public CustomMapView(Context context, GoogleMapOptions options) {
            super(context, options);
        }
    
        public void setCallback(MapFragment.ControlLock callbackControl) {
            this.mCallbackControl = callbackControl;
        }
    
        @Override
        public boolean dispatchTouchEvent(MotionEvent event) {
    
            switch (event.getAction()) {
                case MotionEvent.ACTION_UP:
                    System.out.println("unlocked");
                    mCallbackControl.unlock(); /* Interface */
                    break;
                case MotionEvent.ACTION_DOWN:
                    System.out.println("locked");
                    mCallbackControl.lock(); /* Interface */
                    break;
            }
    
            return super.dispatchTouchEvent(event);
        }
    }
    

提交回复
热议问题