在Google Play商店应用的第5版中,滚动到内容,滚动操作栏,但选项卡已固定在最顶层。
怎么做?
在滚动之前
滚动后
答案 0 :(得分:6)
正如其他人所建议的那样,请使用http://quotesondesign.com/api/3.0/api-3.0.json?callback=json
中的ObservableScrollView
尝试将Toolbar
和SlidingTabStrip
放在同一容器中,然后在用户滚动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>
然后,当您覆盖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://github.com/ksoichiro/Android-ObservableScrollView
答案 1 :(得分:1)
答案 2 :(得分:1)
答案 3 :(得分:1)
很高兴你自己回答你的问题;) 这是另一个小提示: 为选项卡使用单独的布局或将它们集成到工具栏中,然后仅在您看到顶部的选项卡时转换工具栏。