在android中,如何在折叠工具栏布局中放置滚动视图?

在android中,如何在折叠工具栏布局中放置滚动视图?,android,android-layout,scrollview,android-coordinatorlayout,android-collapsingtoolbarlayout,Android,Android Layout,Scrollview,Android Coordinatorlayout,Android Collapsingtoolbarlayout,我想要一个类似于下面所问问题的东西,其中不是“视图1”,而是一个滚动视图: 但它的相对布局并不太长。我的将很长,所以我想把我的布局在滚动视图 我尝试过的代码显示了我的scrollview,但它没有滚动它,而是折叠工具栏 <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/trial" xmlns:androi

我想要一个类似于下面所问问题的东西,其中不是“视图1”,而是一个滚动视图:


但它的相对布局并不太长。我的将很长,所以我想把我的布局在滚动视图

我尝试过的代码显示了我的scrollview,但它没有滚动它,而是折叠工具栏

<ScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/trial"
    xmlns:android="http://schemas.android.com/apk/res/android">

        <LinearLayout
            android:clickable="true"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.CardView
                android:layout_margin="20dp"
                android:layout_width="match_parent"
                android:layout_height="200dp">

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

            <android.support.v7.widget.CardView
                android:layout_margin="20dp"
                android:layout_width="match_parent"
                android:layout_height="200dp">

            </android.support.v7.widget.CardView>
            <android.support.v7.widget.CardView
                android:layout_margin="20dp"
                android:layout_width="match_parent"
                android:layout_height="200dp">

            </android.support.v7.widget.CardView>
            <android.support.v7.widget.CardView
                android:layout_margin="20dp"
                android:layout_width="match_parent"
                android:layout_height="200dp">

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




        </LinearLayout>

    </ScrollView>

能否尝试添加此标记

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

    <ScrollView android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/trial"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
        xmlns:android="http://schemas.android.com/apk/res/android">

----- your code

</ScrollView>
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
-----你的代码
AppBarLayout还需要一个单独的滚动同级,以便知道何时滚动。绑定是通过AppBarLayout.ScrollingViewBehavior类完成的,这意味着您应该将滚动视图的行为设置为AppBarLayout.ScrollingViewBehavior的实例。包含完整类名的字符串资源可用


检查此链接:

您可以尝试在代码中添加以下两行:

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

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