Android的库轻松地创建很酷的动画 [英] Android library to create easily cool animations

查看:191
本文介绍了Android的库轻松地创建很酷的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道酷库做在CSS中一些很酷的动画对象, HTTP://daneden.github .IO / animate.css /

I know a cool library to do some cool object animations in CSS, http://daneden.github.io/animate.css/

是否有任何的Andr​​oid类似的事情?我的意思是,任何库,使动画自如。

Is there any similar thing in Android ? I mean, any library to make animations EASILY.

感谢您

推荐答案

创建动画本身很容易。你并不需要一个库。有哪些适合大多数情况下,还有其他的方式,以动画的东西,但这些是最重要的两个选项:

Creating animations itself is very easy. You don't need a library for that. There are two options which fit most situations, there are other ways to animate stuff but these are the most important ones:


  • 查看动画

  • 对象动画

有不多于它们是如何使用,但他们可以做不同的事情而言这两者之间的差别。

There is not much of a difference between those two in terms of how they are used but they can do different things.

1)查看动画:

有关视图的动画你首先得写动画XML。在这里面你描述的动画应该是什么样子多久它持续。当然你也可以同时创建这些动画编程,但在XML创建他们在大多数情况下,preferable。例如这里有两个动画XML的,一是从顶部滑动的视图下来,另淡出视图了。

For a view animation you first have to write an animation xml. In it you describe what the animation should look like and how long it lasts. You can of course also create those animations programmatically, but creating them in xml is preferable in most situations. For example here are two animation xmls, one slides a view down from the top and the other fades a view out.

滑下:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
            android:fromYDelta="-100%"
            android:toYDelta="0%"
            android:duration="1000"/>
</set>

淡出:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
            android:fromAlpha="1"
            android:toAlpha="0"
            android:duration="700"/>
</set>

比你要加载动画是这样的:

Than you have to load the Animation like this:

Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);

然后你就可以将动画您的看法是这样的:

And then you can apply the animation to your view like this:

linearLayout.startAnimation(slide);

您可以在一个XML结合这些动画,只是把多个翻译/阿尔法/等。标记为一组标记。您可以通过设置延缓设定一个动画开始的 startOffset 是这样的:

You can combine those animations in one xml, just put multiple translate/alpha/etc. tags into one set tag. You can delay the start of one animation in the set by setting the startOffset like this:

android:startOffset="500"

有关完整性:这是你如何编程方式创建一个淡出动画:

For completeness: This is how you would create a fade out animation programatically:

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setStartOffset(offset);
fadeOut.setDuration(duration);

2)对象动画师:

对象动画师可以再次code和XML创建,但XML是在大多数情况下,preferable。这是一个淡出动画将会是什么样对象动画:

Object Animators can again be created in code and xml, but xml is in most cases preferable. This is what a fade out animation would look like with an Object Animator:

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
                android:interpolator="@android:anim/linear_interpolator"
                android:propertyName="alpha"
                android:valueType="floatType"
                android:valueFrom="1.0"
                android:valueTo="0.0"
                android:duration="1000" />

对象的动画看起来可能更复杂一些的开始,但没有太多的XML的差别。有一件事,可以说是让Ob​​jectAnimators preferable查看动画是ObjectAnimators潜在很多更强大,因为他们可以动画pretty任何对象的多的财产。例如围绕它的Y轴并没有多少人知道,这样的事情,甚至有可能下面的动画将旋转视图:

Object animators may look a bit more complicated in the beginning, but there is not much of a difference in the xml. One thing that arguably makes ObjectAnimators preferable to View Animations is that ObjectAnimators are potentially a lot more powerful as they can animate pretty much any property of any object. For example the following animation will rotate a view around it's Y axis and not many people know that something like this is even possible:

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
                android:interpolator="@android:anim/accelerate_decelerate_interpolator"
                android:propertyName="rotationY"
                android:valueType="floatType"
                android:valueFrom="0.0"
                android:valueTo="360.0"
                android:duration="5000"/>

这是你如何编程创建相同的动画:

And this is how you would create the same animation programatically:

ObjectAnimator animation = ObjectAnimator.ofFloat(view, "rotationY", 0.0f, 360f);
animation.setDuration(5000);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
animation.start();

结果是这样的:

您可以从XML应用一个ObjectAnimator动画是这样的:

You can apply an ObjectAnimator animation from xml like this:

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.rotate_axis_y);
set.setTarget(targetView);
set.start();

这篇关于Android的库轻松地创建很酷的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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