Android Scrollview的RequestDisallowWinterCeptTouchEvent

Android Scrollview的RequestDisallowWinterCeptTouchEvent,android,scrollview,touch-event,android-scrollview,google-street-view,Android,Scrollview,Touch Event,Android Scrollview,Google Street View,我有一个街景全景,在线性布局中,在滚动视图中: <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/scrollview"> <LinearLayout android:layout_width="match_parent"

我有一个街景全景,在线性布局中,在滚动视图中:

  <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollview">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/linear">

            <com.google.android.gms.maps.StreetViewPanoramaView
                android:id="@+id/street_view_panorama"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

                <other views - textviews etc>

        </LinearLayout>

    </ScrollView>
编辑:

我尝试过的事情:

我已创建自定义视图,并将代码dispatchTouchEvent导入到我的活动代码中:

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {

        int[] loc = {0, 0};
        mStreetViewPanoramaView.getLocationOnScreen(loc);

        Rect rect = new Rect(loc[0], loc[1] , loc[0] + mStreetViewPanoramaView.getWidth(), loc[1] + mStreetViewPanoramaView.getHeight());


        if (rect.contains((int) event.getRawX(), (int) event.getRawY())) {
            Log.e("stretview", "dispatched");
            return mStreetViewPanoramaView.dispatchTouchEvent(event);
/*            return true;*/

        }else{
            //Continue with touch event
            return super.dispatchTouchEvent(event);
        }
    }

public class CustomStreetViewPanoramaView extends StreetViewPanoramaView {

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

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

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

    public CustomStreetViewPanoramaView(Context context, StreetViewPanoramaOptions options) {
        super(context, options);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return false; // Do not intercept touch event, let the child handle it
    }
}
代码似乎起到了一半的作用-StreetViewParnoramaView可能会获取视图上半部分的触摸事件,但下半部分不会获取任何触摸事件

我的完整布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:id="@+id/container"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollview">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/linearlayout">

            <com.example.simon.customshapes.CustomStreetViewPanoramaView
                android:id="@+id/street_view_panorama"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:id="@+id/card"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hello card"
                    android:layout_gravity="center" />

            </android.support.v7.widget.CardView>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Save panorama"
                android:padding="8dp"
                android:id="@+id/savepano"/>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/my_recycler_view"
                android:scrollbars="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </android.support.v7.widget.RecyclerView>

        </LinearLayout>
    </ScrollView>

</LinearLayout> 

你能试试下面的方法吗

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    int[] loc = {0, 0};
    mStreetViewPanoramaView.getLocationOnScreen(loc);

    Rect rect = new Rect(loc[0], loc[1] , loc[0] + mStreetViewPanoramaView.getWidth(), loc[1] + mStreetViewPanoramaView.getHeight());


    if (rect.contains((int) event.getRawX(), (int) event.getRawY())) {            
        mStreetViewPanoramaView.dispatchTouchEvent(event);
        return true;

    }else{
        //Continue with touch event
        return super.dispatchTouchEvent(event);
    }
}

这将检查触摸是否在全景视图上,并相应地进行处理。

约翰的答案是正确的,但仍然不起作用-这一条将起作用

    @Override
public boolean dispatchTouchEvent(MotionEvent event) {

    if (streetView != null) {
        streetView.getGlobalVisibleRect(rect);

        if (rect.contains((int) event.getRawX(), (int) event.getRawY())) {
            event.offsetLocation(-rect.left, -rect.top);
            streetView.dispatchTouchEvent(event);
            return true;

        } else {
            //Continue with touch event
            return super.dispatchTouchEvent(event);
        }
    } else {
        return super.dispatchTouchEvent(event);
    }
}

dispatchTouchEvent并在将事件偏移到streetView后将其移动

我假定您的意思是创建一个自定义StreetViewPanoramaView类,然后覆盖dispatchTouchEvent。我尝试了你的方法,但没有成功,因为这里的代码是:mStreetViewPanoramaView.dispatchTouchEvent(事件);是循环引用并导致堆栈溢出错误。如果我把电话线拿出来,代码运行,但视图根本无法滚动。我的意思是尝试覆盖活动的dispatch touch事件…或者为主容器布局创建自定义类并覆盖该类。覆盖必须位于scrollview和panorama视图之上。我通过将代码粘贴到我的活动类中尝试了您的代码,我可以看到该条件满足(rect.contains((int)event.getRawX(),(int)event.getRawY())并调用mStreetViewPanoramaView.dispatchTouchEvent(事件);当我尝试在街景上左、右、上、下移动,但街景根本不移动。如果触摸滚动视图的外部,则移动?是。它会移动,我在scrollview中有一个cardview和一个recyclerview,如果我抛出其中任何一个,它们会移动scrollview谢谢。这对我有用。对于希望执行类似操作的任何人,这是正确的代码,您必须将此代码放在活动类中。
    @Override
public boolean dispatchTouchEvent(MotionEvent event) {

    if (streetView != null) {
        streetView.getGlobalVisibleRect(rect);

        if (rect.contains((int) event.getRawX(), (int) event.getRawY())) {
            event.offsetLocation(-rect.left, -rect.top);
            streetView.dispatchTouchEvent(event);
            return true;

        } else {
            //Continue with touch event
            return super.dispatchTouchEvent(event);
        }
    } else {
        return super.dispatchTouchEvent(event);
    }
}