AppBarLayout 内的滚动视图不可滚动

Scollview inside AppBarLayout is not scrollable

抱歉有一段时间没有编程android应用程序,过去我使用 Scrollview 和 linearlayout 并且视图是可滚动的

但是,现在它使用 coordinatorlayout 和 appbarlayout

我尝试了 scrollview 但里面的内容是不可滚动的,所以我发现一些在线讨论是使用 nestscollview ,但仍然没有运气,如何解决?

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:orientation="vertical">




            <TextView
                android:id="@+id/first"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="00:10 When loading an HLS/MP3 stream the current position almost always returns 5-15s in to the stream."
                android:textSize="18sp" />

            <TextView
                android:id="@+id/second"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="00:30 I'm streaming an HLS/MP3 source, starting from zero and setting the setPlayWhenReady to true from the beginning."
                android:textSize="18sp" />


            <TextView
                android:id="@+id/third"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:00 Debug print outs show the when we receive STATE_READY in onPlayerStateChanged the current position returns almost all the time 5-15 seconds into the stream when it in fact should be 0."
                android:textSize="18sp" />


            <TextView
                android:id="@+id/fourth"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:30 When listening to the same stream, but downloaded, it reports 0 (zero) och getCurrentPosition."
                android:textSize="18sp" />

            <TextView
                android:id="@+id/five"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:30 When listening to the same stream, but downloaded, it reports 0 (zero) och getCurrentPosition."
                android:textSize="18sp" />

            <TextView
                android:id="@+id/six"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:30 When listening to the same stream, but downloaded, it reports 0 (zero) och getCurrentPosition."
                android:textSize="18sp" />

            <TextView
                android:id="@+id/seven"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:30 When listening to the same stream, but downloaded, it reports 0 (zero) och getCurrentPosition."
                android:textSize="18sp" />

        </LinearLayout>

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


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

非常感谢

您需要 CoordinatorLayout 并在 NestedScrollView 中使用标记 app:layout_behavior="@string/appbar_scrolling_view_behavior" 来滚动,因此您的布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<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"
    xmlns:card="http://schemas.android.com/tools"
    android:id="@+id/rootLayout"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            android:fitsSystemWindows="true">

       <!-- Toolbar and ImageView... or other -->

        </android.support.design.widget.CollapsingToolbarLayout>

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

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

     <!-- Your TextView -->

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

</android.support.design.widget.CoordinatorLayout>