Android PropertyAnimation官网文档翻译

点击打开官方Animation文档

简述:

能不用PropertyAnimation就不用,如果只是做View就用ViewPropertyAnimator多个属性一起改。ViewAnimation并没有改变View的属性,点击还是原来区域。


Property Animation 和 View Animation

ViewAnimation有很强的局限性:只能操作View对象、View的部分属性(不包含背景色)、只是改变View在哪里绘制,没有改变相应逻辑(比如Button移动,你点击的地方仍旧是以前的,相应逻辑需要你自己写)。

因为ViewAnimation改变View的绘制,所以是通过操控他的父View,ViewGroup来完成的,因为View本身没有这样的属性。所以View对象本身没有变化,导致View的行为操作,仍旧停留在原来区域。3.0后添加了get、set方法,就行bug修复。

而PropertyAnimation可以View对象的真实属性(调用方法),所以View会自动调用invalidate方法(View set方法会调)

然而ViewAnimation体系启动时间更少、需要代码更少。所以了ViewAnimation够用了,就别用PropertyAnimation。


PropertyAnimation API:

ValueAnimator
就是指定数值区间、时间,然后在监听器中做你想做的事情(如动画)。(也就是改什么属性是你在回调中写的,实际上你只控制了速度),Animation有两个阶段:算数值、设置对象的属性值。  ValueAnimator只负责第一个阶段,第二个阶段程序员自己写。

获取数值的API是getAnimatedValue()

ValueAnimator animation = ValueAnimator.ofFloat(0f, 1f);
animation.setDuration(1000);
animation.start();
ValueAnimator animation = ValueAnimator.ofObject(new MyTypeEvaluator(), startPropertyValue, endPropertyValue);
animation.setDuration(1000);
animation.start();

ObjectAnimator
上述的两个阶段都负责,所以要指定属性名称。类需要提供set和get方法,方法的命名方式要符合驼峰命名。如alpha属性,要有个setAlpha,getAlpha防范。如果三个次,如helloWorld,那set方法就是setHelloWorld

ObjectAnimator anim = ObjectAnimator.ofFloat(foo, "alpha", 0f, 1f);
anim.setDuration(1000);
anim.start();
  根据不同的属性值,你可能需要调用invalidate方法,在 onAnimationUpdate()  这个回调中调用。例如Drawable对象的color属性,就只有你主动调用才刷新。而View类的所有带set***方法的属性***都会自己主动刷新,就不用你再调用了。


AnimatorSet:
就是让多个Animator,按照某种顺序发生(同时了、一个结束了、一个开始了)。

AnimatorSet bouncer = new AnimatorSet();
bouncer.play(bounceAnim).before(squashAnim1);
bouncer.play(squashAnim1).with(squashAnim2);
bouncer.play(squashAnim1).with(stretchAnim1);
bouncer.play(squashAnim1).with(stretchAnim2);
bouncer.play(bounceBackAnim).after(stretchAnim2);
ValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
fadeAnim.setDuration(250);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(bouncer).before(fadeAnim);
animatorSet.start();		

对ViewGroup布局的改变:

使用LayoutTransition

  • APPEARING - A flag indicating the animation that runs on items that are appearing in the container.
  • CHANGE_APPEARING - A flag indicating the animation that runs on items that are changing due to a new item appearing in the container.
  • DISAPPEARING - A flag indicating the animation that runs on items that are disappearing from the container.
  • CHANGE_DISAPPEARING - A flag indicating the animation that runs on items that are changing due to an item disappearing from the container.


使用Interpolator:

加速器提供时间和返回值之间的映射关系。自己写就继承TimeInterpolator,或者用android.view.animation包里的。

AccelerateDecelerateInterpolator

public float getInterpolation(float input) {
    return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f;
}



监听器:实现接口Animator.AnimatorListener,或者有空方法让你重写的AnimatorListenerAdapter类。


使用自定义的TypeEvaluator:

public class FloatEvaluator implements TypeEvaluator {

    public Object evaluate(float fraction, Object startValue, Object endValue) {
        float startFloat = ((Number) startValue).floatValue();
        return startFloat + fraction * (((Number) endValue).floatValue() - startFloat);
    }
}


监听关键的帧:

Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
Keyframe kf1 = Keyframe.ofFloat(.5f, 360f);
Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
ObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(target, pvhRotation)
rotationAnim.setDuration(5000ms);

新增API中的属性:

  • translationX and translationY: These properties control where the View is located as a delta from its left and top coordinates which are set by its layout container.
  • rotationrotationX, and rotationY: These properties control the rotation in 2D (rotationproperty) and 3D around the pivot point.
  • scaleX and scaleY: These properties control the 2D scaling of a View around its pivot point.
  • pivotX and pivotY: These properties control the location of the pivot point, around which the rotation and scaling transforms occur. By default, the pivot point is located at the center of the object.
  • x and y: These are simple utility properties to describe the final location of the View in its container, as a sum of the left and top values and translationX and translationY values.
  • alpha: Represents the alpha transparency on the View. This value is 1 (opaque) by default, with a value of 0 representing full transparency (not visible).

例子


ViewPropertyAnimator:

对比:

Multiple ObjectAnimator objects

ObjectAnimator animX = ObjectAnimator.ofFloat(myView, "x", 50f);
ObjectAnimator animY = ObjectAnimator.ofFloat(myView, "y", 100f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();

One ObjectAnimator

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 50f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 100f);
ObjectAnimator.ofPropertyValuesHolder(myView, pvhX, pvyY).start();

ViewPropertyAnimator

myView.animate().x(50f).y(100f);

使用XML:

为了区分ViewAnimation,需要在res/animator/目录取代res/anim/目录,要预览的话,系统只会在上述路径下扫描PropertyAnimation


<set android:ordering="sequentially">
    <set>
        <objectAnimator
            android:propertyName="x"
            android:duration="500"
            android:valueTo="400"
            android:valueType="intType"/>
        <objectAnimator
            android:propertyName="y"
            android:duration="500"
            android:valueTo="300"
            android:valueType="intType"/>
    </set>
    <objectAnimator
        android:propertyName="alpha"
        android:duration="500"
        android:valueTo="1f"/>
</set>

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
    R.anim.property_animator);
set.setTarget(myObject);
set.start();






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了小程序应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!
提供的源码资源涵盖了小程序应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!
### 回答1: Android API 帮助文档是一份由谷歌提供的关于Android操作系统的API(应用程序编程接口)文档。这份文档以中文撰写,方便本地华语开发者使用。它包含了Android操作系统中各种功能和服务的详细介绍,以及开发者在编写Android应用程序时所需要了解的相关知识和技术。 Android API帮助文档的内容非常丰富,涵盖了从基础的应用程序开发知识到高级的操作系统特性的各个方面。开发者可以通过查找特定的API来获取关于某个功能或服务的详细说明和用法示例。文档中的示例代码和解释能够帮助开发者更好地理解API的使用方法,并为他们提供参考和指导。 此外,Android API帮助文档还提供了一些关于Android开发工具和环境的说明,如Android Studio的使用指南和调试技巧。它还包含了一些开发者常见问题的解答和技术支持资源的链接,便于开发者解决问题和获取帮助。 总之,Android API帮助文档是一份非常重要且实用的资源,它为开发者提供了丰富的知识和工具,帮助他们编写出高质量的Android应用程序。无论是新手还是有经验的开发者,都可以从中获得必要的指导和支持,提升他们的技术水平和开发效率。 ### 回答2: Android API帮助文档是一份由谷歌翻译的中文版本的安卓帮助文档。它提供了关于安卓应用程序开发所需的各种API(应用程序接口)的详细信息和说明。 这份帮助文档包含了安卓软件开发所需的所有必要信息,从基本的概念到高级的功能。它包含了安卓平台的每个版本在API上的变化,以及每个类、方法和属性的使用说明。 文档中的内容非常全面,覆盖了安卓框架中的各个方面,包括用户界面设计、多媒体处理、数据存储、网络通信、传感器、位置服务等等。而且这份文档是由谷歌翻译的中文版,以确保中国开发者能够更好地理解和应用这些API。 通过这份文档,开发者可以方便地查找所需的功能和方法,并了解其用法和参数。这对于初学者来说非常有帮助,因为他们可以通过这份文档快速入门,并逐步学习和掌握更高级的技术。 总的来说,Android API帮助文档谷歌翻译版中文文档对于中国开发者来说是一份非常宝贵的资料。它为开发者提供了方便快捷的查询和学习资源,帮助他们更好地开发出高质量、功能强大的安卓应用程序。 ### 回答3: Android API帮助文档是谷歌翻译的中文版本,提供了关于安卓开发技术的详细说明和指导。它是Android开发人员必备的文档资源之一。 Android API帮助文档详细介绍了Android系统的各个组件、类和方法的用法和功能,包括用户界面、数据存储、网络通信、多媒体处理等方面。开发人员可以通过查阅这些文档来了解Android开发框架的细节,学习如何使用Android提供的各种功能和工具。 Android API帮助文档使用谷歌翻译进行中文翻译,确保了开发人员可以清晰地理解文档中的内容。谷歌翻译具有较高的可靠性和准确性,在对术语和句子进行翻译时能够提供较好的表达和语法。 通过Android API帮助文档,开发人员可以方便地查找和获取关于Android开发的指导和解决方案。文档提供了详细的示例代码和实践建议,帮助开发人员更好地理解和应用Android开发技术。 总之,Android API帮助文档是谷歌翻译的中文版本,为Android开发人员提供了理解和掌握Android开发技术的重要资源。开发人员可以通过查阅文档中的内容来学习和解决Android开发中的问题,提高开发效率和质量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值