【发布时间】:2014-12-09 23:06:51
【问题描述】:
我使用了 Google IO 存储库中的代码: https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/BaseActivity.java
我试图在向上滚动时隐藏工具栏,效果很好,但我的问题是,当工具栏在屏幕外显示动画时,我的主要内容保持固定不变。
在R.id.toolbar_actionbar上运行动画的代码是:
view.animate()
.translationY(-view.getBottom())
.alpha(0)
.setDuration(HEADER_HIDE_ANIM_DURATION)
.setInterpolator(new DecelerateInterpolator());
我尝试将工具栏放在带有内容的线性布局中,但它没有改变任何东西。只有当我将操作栏设置为 visibility=gone 时,内容才会向上移动。
有谁知道我必须做什么才能使内容与工具栏的翻译动画一起制作动画?
基本上,问题归结为:如何为一个视图的位置设置动画,并让其他视图用它动画?
Google IO 代码似乎只是为工具栏设置动画,其余内容也随之动画,但我无法让它工作。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar_actionbar"
layout="@layout/toolbar_actionbar" />
<FrameLayout
android:id="@+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adsContainer"
android:layout_below="@+id/toolbar_actionbar" />
<LinearLayout
android:id="@+id/adsContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#000000"
android:orientation="horizontal" />
</RelativeLayout>
<!-- The navigation drawer -->
<ExpandableListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
标签: android android-5.0-lollipop