【问题标题】:Android - Blank space remains after view is translatedAndroid - 翻译视图后仍有空白
【发布时间】:2015-03-03 20:32:17
【问题描述】:

我正在尝试为我的工具栏(用作 ActionBar)设置动画以在滚动后隐藏自身。我正在使用以下代码向上翻译工具栏 -

toolbar.animate().translationYBy(toolbar.getBottom()*(-1));

但是,动画结束后,工具栏之前占用的空间会变成白色并保留在那里。

我想让工具栏下方的内容上移,占据工具栏留下的空间。

【问题讨论】:

  • 我也有同样的问题任何解决方案

标签: android android-actionbar android-animation


【解决方案1】:

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

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

  1. 使工具栏覆盖内容

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

    <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>
    

  1. 将工具栏放在内容上方

    在为工具栏设置动画时,您还必须为 Activity 的布局设置动画以取代它的位置。实施细节将取决于您展示的内容。对于RecyclerView,请参阅this blog

  1. 隐藏ActionBar

    只需请求操作栏getSupportActionBar().hide() 隐藏并重新绘制窗口。

此外,如果您希望进行全屏 Immersive 活动,这应该涵盖这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    相关资源
    最近更新 更多