Search code examples
androidscrollandroid-scrollviewandroid-appbarlayout

Scollview inside AppBarLayout is not scrollable


Sorry for not programming android app for a while, in the past I use Scrollview with linearlayout and the view is scrollable

However, right now it use the coordinatorlayout and appbarlayout

I tried scrollview but content inside is not scorllable, so I found some online discussion is use nestscollview , but still no luck, how to fix it?

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

Thanks a lot


Solution

  • You need a CoordinatorLayout and in NestedScrollView with tag app:layout_behavior="@string/appbar_scrolling_view_behavior" to be scrollable, so your layout look like this:

    <?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>