动画如何隐藏ActionBar并保留标签?

Cíc*_*ura 3 android android-animation android-viewpager android-actionbar

在Google Play商店应用的第5版中,滚动到内容,按下滚动操作栏,但选项卡已修复以显示在顶部.

这该怎么做?

在滚动之前

在此输入图像描述

滚动后

在此输入图像描述

mem*_*izr 6

正如其他人所建议的那样,请使用ObservableScrollView:https://github.com/ksoichiro/Android-ObservableScrollView

尝试把两个ToolbarSlidingTabStrip在同一容器中,然后动态显示容器作为用户滚动ObservableScrollView,例如:

<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>
Run Code Online (Sandbox Code Playgroud)

然后,当你覆盖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);
    }
}
Run Code Online (Sandbox Code Playgroud)

这些onUpOrCancelMotionEvent东西是为容器设置动画,以防止工具栏只显示/隐藏一半.

以下是仅供参考的演示视频:https://drive.google.com/file/d/0B7TH7VeIpgSQSzZER1NneWpYa1E/view?usp=sharing