Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 在NestedScrollView里面的MapView不滚动大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
像这样在xml中膨胀我的Mapview
<android.support.v4.widget.nestedScrollView
        android:id="@+id/sv_offers"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="56dp"
        android:visibility="gone"
        app:layouT_Behavior="@String/appbar_scrolling_view_behavior">

        <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>

我已经实现了@L_914_0@mapview如下: –

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:
                if (null == mViewParent) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                    Timber.d("Inside if of action down");
                } else {
                    mViewParent.requestDisallowInterceptTouchEvent(true);
                    Timber.d("Inside else of action down");
                }
                break;
            case MotionEvent.ACTION_UP:
                if (null == mViewParent) {
                    getParent().requestDisallowInterceptTouchEvent(false);
                    Timber.d("Inside if of action up");
                } else {
                    mViewParent.requestDisallowInterceptTouchEvent(false);
                    Timber.d("Inside else of action up");
                }
                break;
            default:
                break;
        }

        return super.onInterceptTouchEvent(event);
    }
}

并在我的Activity的onCreate()中使用了mapview

@H_632_2@mapView = (CustomMapView) findViewById(R.id.mapView); mapView.onCreate(savedInstanceStatE); GoogleMap googleMap = mapView.getMap(); googleMap.setMyLOCATIOnEnabled(false); googleMap.getUiSetTings().setMyLOCATIOnButtonEnabled(false); googleMap.getUiSetTings().setCompassEnabled(false); googleMap.getUiSetTings().setAllGesturesEnabled(false); mapView.setViewParent(nestedScrollContainer);

其中nestedScrollContainer是我的嵌套scrollView.Tried在SO中提供了许多变通办法,但似乎无法获得滚动问题的解决方法.帮助将不胜感激!谢谢

解决方法

你的@L_931_3@mapView里面的nestedScrollView – >的LinearLayout – > com.xys.widgets.CustomMapView两级层次结构.

因此,在您的情况下,您可以访问nestedScrollView,如下所示

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

改变这一行
.的getParent()requestDisallowInterceptTouchEvent(真);对此

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

以下是您的案例的完整代码

<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,int defStylE) {
            super(context,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);
        }
    }

大佬总结

以上是大佬教程为你收集整理的android – 在NestedScrollView里面的MapView不滚动全部内容,希望文章能够帮你解决android – 在NestedScrollView里面的MapView不滚动所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。