Reputation: 33
I am using the following layout file to implement a coordinator layout with collapsing toolbar (when the user scrolls down, it should collapse, and reappear when they scroll up) However, this scroll off screen/collapse functionality is not working, and I don't know why. Instead of reacting, the toolbar, and tab bar stay statically at the top of the screen.
<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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Alpha" />
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Beta" />
<!-- a bunch of content just to make the view long enough to scroll -->
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Upsilon" />
</LinearLayout>
</ScrollView>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorAccent"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<!-- ^^^^^^^^^^^^^^^^^^ -->
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways" />
<!-- ^^^^^^^^^^^^^^^^^^ -->
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_padding"
android:src="@drawable/ic_add"/>
</android.support.design.widget.CoordinatorLayout>
Any help? Thanks!
Upvotes: 3
Views: 1726
Reputation: 2041
As far as I know, ScrollView does not work. You can use NestedScrollView or RecyclerView instead.
Upvotes: 8