How does an animation hide an ActionBar and save tabs?

In version 5 of the Google Play Store app, scroll to the content, the ActionBar scrolls, but the tabs are fixed to get on top.

How to do it?

BEFORE SCROLL

enter image description here

AFTER CONTROL

enter image description here

+3
source share
4 answers

Like others, use ObservableScrollViewfrom: https://github.com/ksoichiro/Android-ObservableScrollView

Try to put both tags Toolbarand SlidingTabStripin the same container, and then animate this container when the user scrolls ObservableScrollView, for example:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         tools:context=".MainActivity">

    <com.github.ksoichiro.android.observablescrollview.ObservableListView
        android:id="@+id/listView"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

    <LinearLayout
        android:id="@+id/toolbarContainer"
        android:orientation="vertical"
        android:elevation="10dp"
        android:background="@color/material_deep_teal_200"
        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"/>

            <!--Placeholder view, your tabstrip goes here-->
            <View
                android:layout_width="wrap_content"
                android:layout_height="48dp"/>
   </LinearLayout>
</FrameLayout>

, ObservableScrollViewCallbacks, - :

@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {

    toolbarContainer.animate().cancel();

    int scrollDelta = scrollY - oldScrollY;
    oldScrollY = scrollY;

    float currentYTranslation = -toolbarContainer.getTranslationY();
    float targetYTranslation = Math.min(Math.max(currentYTranslation + scrollDelta, 0), toolbarHeight);
    toolbarContainer.setTranslationY(-targetYTranslation);
}

@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    float currentYTranslation = -toolbarContainer.getTranslationY();
    int currentScroll = listView.getCurrentScrollY();

    if (currentScroll < toolbarHeight) {
        toolbarContainer.animate().translationY(0);
    } else if (currentYTranslation > toolbarHeight /2) {
        toolbarContainer.animate().translationY(-toolbarHeight);
    } else {
        toolbarContainer.animate().translationY(0);
    }
}

onUpOrCancelMotionEvent , /.

: https://drive.google.com/file/d/0B7TH7VeIpgSQSzZER1NneWpYa1E/view?usp=sharing

+5

:

https://github.com/ksoichiro/Android-ObservableScrollView : D

This library is great for my case and for very others.

+1
source

It’s great that you yourself will answer your question;) Here is another small hint: Use a separate layout for your tabs or integrate them into your toolbar, and then translate the toolbar only until you see the tabs on top.

+1
source

All Articles