Android 动画如何隐藏动作栏并保持标签?
在Google Play Store应用程序的第5版中,滚动到内容,操作栏继续滚动,但标签固定在顶部 如何做到这一点 在滚动之前 滚动后Android 动画如何隐藏动作栏并保持标签?,android,android-actionbar,android-viewpager,android-animation,Android,Android Actionbar,Android Viewpager,Android Animation,在Google Play Store应用程序的第5版中,滚动到内容,操作栏继续滚动,但标签固定在顶部 如何做到这一点 在滚动之前 滚动后 看看这些链接(特别是第二个链接): 答案如下: :D 这个库非常适合我和其他人的案例很好,你可以自己回答问题;) 下面是另一个小提示: 为选项卡使用单独的布局,或将它们集成到工具栏中,然后仅在可以看到顶部选项卡的范围内传输工具栏 正如其他人所建议的那样,从以下位置使用ObservableScrollView: 尝试将工具栏和滑动条放在同一个容器中,然后在用
看看这些链接(特别是第二个链接): 答案如下: :D
这个库非常适合我和其他人的案例很好,你可以自己回答问题;) 下面是另一个小提示:
为选项卡使用单独的布局,或将它们集成到工具栏中,然后仅在可以看到顶部选项卡的范围内传输工具栏 正如其他人所建议的那样,从以下位置使用
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>
onProjectancelMotionEvent
功能是为容器设置动画,以防止工具栏只显示/隐藏了一半
这里有一个演示视频仅供参考:您的主布局是什么样子的?您似乎只更改工具栏的Y位置。我想知道listview和toolbarcontainer的父布局以及它们之间的关系HP。
ObservableListView
和toolbarcontainer都是sibling,嵌套在同一父级中。我在示例中添加了父布局和observeListView
。我希望它能有所帮助。根据您的示例,scrollview的顶部位于工具栏下。是否将空视图添加到具有工具栏高度的scrollview?或者你不需要像使用边距或填充物一样压缩这个重叠部分吗?是的,它们重叠。根据具体情况,两种方法都可以。如果使用填充,则必须在父布局中设置android:clipToPadding=“false”
,以避免切断列表视图。但是,我通常选择空标题路线,因为在我看来,它为我的用例提供了更多的灵活性。@Splatters您好,我正在尝试在一个片段上实现它,在我的活动中有选项卡,如何添加动画?
@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);
}
}