NestedScrollView里面的MapView不能平滑滚动

时间:2017-12-10 18:32:23

标签: android xml google-maps scrollview

我在NestedScroollView中遇到了MapView问题。 我的谷歌地图显示正确但是,当我尝试滚动地图时它不起作用。我不知道如何解决这个问题。谁能帮我?谢谢!

这是我的代码: Dog_view.xml

print('ops/sec: {0}, msec: {1}'.format(all_numbers[5], all_numbers[9]))

dog_view_layout.xml

...
<android.support.v4.widget.NestedScrollView
    android:fillViewport="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/nestedScroll"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <include layout="@layout/dog_view_layout"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

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

DogFragment

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:background="#000"
    android:layout_height="wrap_content"
    android:paddingTop="20dp">
    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

3 个答案:

答案 0 :(得分:3)

您必须创建自定义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);
   }
}

在XML中,请遵循以下代码:

<com.hantash.nadeem.custom_views.AppMapView
   android:id="@+id/map_ride_route"
   android:layout_width="match_parent"
   android:layout_height="220dp"
   android:layout_margin="10dp"/>

答案 1 :(得分:0)

我遇到了同样的问题。这是解决方案。我做了一个自定义的MapView并覆盖了onTouchEvent()。

 @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;
}

答案 2 :(得分:0)

这是正在寻找Kotlin的CustomMapView代码。

if country is None:
    Devices = GatewayDevice.objects.prefetch_related("model").filter(end_date=None)
else:
    Devices = GatewayDevice.objects.prefetch_related("model").filter(
            model__site__country=country, end_date=None
        )