Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 嵌套滚动视图内的MapView滚动不平滑_Android_Xml_Google Maps_Scrollview - Fatal编程技术网

Android 嵌套滚动视图内的MapView滚动不平滑

Android 嵌套滚动视图内的MapView滚动不平滑,android,xml,google-maps,scrollview,Android,Xml,Google Maps,Scrollview,NestedScrollView中的地图视图有问题。 我的谷歌地图显示正确,但当我尝试滚动地图时,它不起作用。我不知道怎么解决这个问题。有人能帮我吗?谢谢 这是我的密码: Dog_view.xml ... <android.support.v4.widget.NestedScrollView android:fillViewport="true" android:layout_width="match_parent" android:layout_height="m

NestedScrollView中的地图视图有问题。 我的谷歌地图显示正确,但当我尝试滚动地图时,它不起作用。我不知道怎么解决这个问题。有人能帮我吗?谢谢

这是我的密码: Dog_view.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>

我也有同样的问题。这是解决办法。我制作了一个自定义的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;
}

我也有同样的问题。这是解决办法。我制作了一个自定义的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;
}

您必须创建自定义地图视图。按照下面提供的代码片段进行操作

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

您必须创建自定义地图视图。按照下面提供的代码片段进行操作

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

下面是正在查找Kotlin的CustomMapView代码

class CustomMapView(context: Context, attributeSet: AttributeSet) : MapView(context, attributeSet) {

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
    when (ev.action) {
        MotionEvent.ACTION_UP -> parent.requestDisallowInterceptTouchEvent(false)
        MotionEvent.ACTION_DOWN -> parent.requestDisallowInterceptTouchEvent(true)
    }
    return super.dispatchTouchEvent(ev)
 } 
}

下面是正在查找Kotlin的CustomMapView代码

class CustomMapView(context: Context, attributeSet: AttributeSet) : MapView(context, attributeSet) {

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
    when (ev.action) {
        MotionEvent.ACTION_UP -> parent.requestDisallowInterceptTouchEvent(false)
        MotionEvent.ACTION_DOWN -> parent.requestDisallowInterceptTouchEvent(true)
    }
    return super.dispatchTouchEvent(ev)
 } 
}

我尝试了你的解决方案,但仍然无效。我无法水平滚动我的CustomMapView…请检查@FedericoI下面的我的答案我尝试了你的解决方案,但仍然无效。我无法水平滚动我的CustomMapView…请检查@Federico下面的我的答案