MapView inside NestedScrollView not scrolling

て烟熏妆下的殇ゞ 提交于 2019-11-30 14:14:53
Hardik

In your code MapView inside NestedScrollView--> LinearLayout--> com.xys.widgets.CustomMapView Two level hierarchy.

So in your case you can access NestedScrollView like below

getParent().getParent().requestDisallowInterceptTouchEvent(true); 

Change this line getParent().requestDisallowInterceptTouchEvent(true); to this

getParent().getParent().requestDisallowInterceptTouchEvent(true);

Below is full code for your case

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.xys.widgets.CustomMapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="125dp"/>


    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

`

public class CustomMapView extends MapView {

        private ViewParent mViewParent;

        public CustomMapView(Context context) {
            super(context);
        }

        public CustomMapView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public CustomMapView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

        public void setViewParent(@Nullable final ViewParent viewParent) { //any ViewGroup
            mViewParent = viewParent;
        }

        public CustomMapView(Context context, GoogleMapOptions options) {
            super(context, options);
        }

        @Override
        public boolean onInterceptTouchEvent(final MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:

                        getParent().getParent().requestDisallowInterceptTouchEvent(true);
                        Timber.d("Inside if of action down");
                    break;
                case MotionEvent.ACTION_UP:

                        getParent().getParent().requestDisallowInterceptTouchEvent(false);
                        Timber.d("Inside if of action up");

                    break;
                default:
                    break;
            }

            return super.onInterceptTouchEvent(event);
        }
    }

It is possible to get almost square MapView inside NestedScrollView.

    //Fix map height
    ViewGroup.LayoutParams lp = mapView.getLayoutParams();
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    lp.height = metrics.widthPixels;
    mapView.setLayoutParams(lp);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!