android - 在具有位置依赖性的 View 上转换动画

标签 android animation translate-animation

我遇到了一个问题,我有一个标题 View ,我想将其转换为可见性——使用转换动画——它位于主内容 View 的正上方。为了说明我的意思,请看下图。蓝色部分是标题,橙色部分是主要内容。

enter image description here

示例代码

TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -rlInfoBar.getHeight());
        animation.setFillAfter(true);
        animation.setDuration(10000);

        animation.setAnimationListener(new TranslateAnimation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        rvItems.startAnimation(animation);
        rlInfoBar.startAnimation(animation);

当我翻译蓝色部分时,即使主要部分被声明为“android:layout_below="@+id/",它仍然保留在原位。我的想法是然后将它们都翻译,但是,在这样做时主要内容向上移动,但屏幕底部也向上移动,显示父 View 的背景。如何解决这个问题?我是否必须平移两个 View 并拉伸(stretch)主要内容 View 或以某种方式将主要内容 View 锚定到底部屏幕的?

翻译两个 View 的结果

enter image description here

最佳答案

Do I have to translate both views plus stretch the main content view or somehow anchor the main content view to the bottom of the screen?

好吧,如果你不拉伸(stretch)主要内容 View 然后将其锚定到底部将导致在标题 View 出现时顶部出现间隙向上移动。所以我认为您需要一组动画(缩放和平移)。

或者您使用 Transition framework ,在这种情况下,ChangeBounds 转换将为两个 View

完成工作
View sceneRoot = <someViewGroupContainingBothViews>;
TransitionManager.beginDelayedTransition(sceneRoot, new ChangeBounds());
rlInfoBar.setY(<newY_CoordinateOfHeaderView>);

关于android - 在具有位置依赖性的 View 上转换动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49212119/

相关文章:

android - 如何使用腻子向安卓手机发送消息?

javascript - 焦点在 android 上不起作用

android - 从上到下 - 翻译动画

javascript - 如何在Vue中使用 "v-for"语句为 "v-if"元素创建动画?

jquery - bxslider 文字效果 animate.css

java - 查找 TranslateTransition 的两个节点之间的距离

java - 如何创建自定义插值器以在 android 中应用翻译动画

android - 如何对角地翻译图像上的动画?

android - 以编程方式更改从 API 响应获得的颜色资源的值

java - 在android中从两个不同的 Activity 添加两个Double值