Android - 翻译视图后仍留有空白区域

jai*_*rik 7 android android-animation android-actionbar

我试图动画我的工具栏(用作ActionBar)在滚动后隐藏自己.我使用以下代码翻译工具栏 -

toolbar.animate().translationYBy(toolbar.getBottom()*(-1));
Run Code Online (Sandbox Code Playgroud)

但是,在动画之后,之前工具栏占用的空间变为白色并保持不变.

我希望工具栏下方的内容向上移动并占据工具栏留下的空间.

dob*_*dog 0

工具栏动画后出现 \xe2\x80\x99s 白色背景的原因是它嵌入布局中的方式。

\n\n

有几种方法可以实现这一目标:

\n\n
    \n
  1. 让工具栏覆盖内容

    \n\n

    使用FrameLayout保存工具栏和活动内容。

    \n\n
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"\n        android:layout_width="match_parent"\n        android:layout_height="match_parent">\n\n    <ImageView\n        android:id="@+id/picture"\n        android:layout_width="match_parent"\n        android:layout_height="match_parent"\n        android:scaleType="centerCrop"\n        android:src="@drawable/jokic" />\n\n    <android.support.v7.widget.Toolbar\n        android:id="@+id/toolbar"\n        android:layout_width="match_parent"\n        android:layout_height="wrap_content"\n        android:background="@android:color/holo_blue_dark" />\n\n</FrameLayout>\n
    Run Code Online (Sandbox Code Playgroud)
  2. \n
\n\n

全屏模式

\n\n
    \n
  1. 将工具栏保持在内容上方

    \n\n

    当您为工具栏设置动画时,您还必须为活动的布局设置动画以取代它的位置。实施细节将取决于您所展示的内容。如需RecyclerView查看此博客

  2. \n
\n\n

全屏模式

\n\n
    \n
  1. 隐藏ActionBar

    \n\n

    只需请求隐藏操作栏getSupportActionBar().hide()即可重绘窗口。

  2. \n
\n\n

在此输入图像描述

\n\n

另外,如果您想要进行全屏沉浸式体验活动,这应该涵盖了这一点。

\n