安卓objectanimator扩大从上到下动画/崩溃? [英] android objectanimator expand/collapse from top to bottom animation?

查看:816
本文介绍了安卓objectanimator扩大从上到下动画/崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试不同的方法来获得与物体动画展开/折叠的动画,但他们都不到目前为止的工​​作。

我已经使用该解决方案和它的作品,但是当我看到它说,它更preferred文档使用动画永久动画对象,而不是动画。

我的code问题是,它总是从视图顶部开始,但我需要展开/折叠从底部的视图。

这是我的code:

 公共布尔崩溃(查看视图,诠释开始,诠释完)
{
    AnimatorSet套=新AnimatorSet();
    ObjectAnimator A = ObjectAnimator.ofFloat(看来,translationY,开始,结束);
    set.play(一);
    set.setDuration(3000L);
    set.setInterpolator(新LinearInterpolator());
    set.addListener(新AnimatorListenerAdapter()
    {
        @覆盖
        公共无效onAnimationEnd(动画动画)
        {
        }
    });
    set.start();
    返回true;
}


解决方案

使用ObjectAnimator.ofInt并使用底部的属性名尝试。这将动画开始在视图的底部。 TranslationY对应于视图的顶部。

I've been trying different approaches to get the expand/collapse animation with object animator but none of them so far worked.

I have used this solution and it works, but when I read the documentation it says it's more preferred to use animator to permanently animate objects rather than animation.

Problem with my code is that it always starts from top of the view, and yet I need to expand/collapse the view from bottom.

here is my code:

public boolean collapse( View view, int start, int end )
{
    AnimatorSet set = new AnimatorSet();
    ObjectAnimator a = ObjectAnimator.ofFloat( view, "translationY", start, end );
    set.play( a );
    set.setDuration( 3000L );
    set.setInterpolator( new LinearInterpolator() );
    set.addListener( new AnimatorListenerAdapter()
    {
        @Override
        public void onAnimationEnd( Animator animation )
        {
        }
    } );
    set.start();
    return true;
}

解决方案

Trying using an ObjectAnimator.ofInt and use the property name of "Bottom". That will animate starting on the bottom of the view. TranslationY corresponds to the top of the view.

这篇关于安卓objectanimator扩大从上到下动画/崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆