是否可以将ScrollView添加到AppBarLayout

use*_*863 5 android android-scrollview android-coordinatorlayout android-nestedscrollview

我需要和两个人一起工作ScrollView.一个在里面AppBarLayout,另一个在外面.

对于外界ScrollView,我使用的是NestedScrollViewappbar_scrolling_view_behavior它的工作正常.

对于里面,我使用的是Scrollviewapp:layout_scrollFlags="scroll|enterAlways|snap"

我的问题是,NestedScrollView似乎覆盖了ScrollView事件,即使我触摸该ScrollView区域,NestedScrollView也就是滚动的事件.

有什么办法可以吗?

请参阅以下代码:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"    
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@android:color/white"
            app:layout_scrollFlags="scroll|enterAlways|snap">

            <TextView                
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>  

        </ScrollView>       
     </android.support.design.widget.AppBarLayout>

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

        <TextView                
               android:layout_width="match_parent"
               android:layout_height="wrap_content"/>   

    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

Ash*_*ngh 5

也许这会奏效:

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"    
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@android:color/white"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        android:id="@+id/scr">

        <TextView                
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>  

    </ScrollView>       
 </android.support.design.widget.AppBarLayout>

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

    <TextView                
           android:layout_width="match_parent"
           android:layout_height="wrap_content"/>   

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

ScrollView scr = (ScrollView) findViewById(R.id.scr);
scr.setOnTouchListener(new ScrollView.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            // Disallow ScrollView to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(true);
            break;

        case MotionEvent.ACTION_UP:
            // Allow ScrollView to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }

        // Handle ScrollView touch events.
        v.onTouchEvent(event);
        return true;
    }
});
Run Code Online (Sandbox Code Playgroud)

它将覆盖滚动视图中的scroll方法.