我正在尝试动画我的工具栏(用作ActionBar)以在滚动后隐藏自己。我使用以下代码翻译工具栏 -
toolbar.animate().translationYBy(toolbar.getBottom()*(-1));
然而,在动画之后,之前工具栏占用的空间变为白色并保持不变。
我希望工具栏下方的内容向上移动并占据工具栏留下的空间。
答案 0 :(得分:0)
动画工具栏后出现白色背景的原因是它在布局中的嵌入方式。
有几种方法可以实现这一目标:
使工具栏覆盖内容
使用FrameLayout
同时保存工具栏和Activity的内容。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/jokic" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_dark" />
</FrameLayout>