博客
关于我
255_属性动画解析
阅读量:145 次
发布时间:2019-02-28

本文共 1116 字,大约阅读时间需要 3 分钟。

属性动画在Android开发中是一个强大的工具,能够通过代码实现丰富的视觉效果。以下将详细介绍如何使用ObjectAnimator类来实现属性动画。

属性动画的实现

属性动画的实现主要依赖于ObjectAnimator类。这类动画可以通过设置目标视图(View)的属性并提供初始值、目标值和动画时间来实现。例如,可以通过以下代码创建一个缩放Y轴的动画:

ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "scaleY", 1f, 3f, 1f).setDuration(3000).start();

需要注意的是,ObjectAnimator支持的属性取决于目标View实现了哪些接口。例如,TextView类支持以下属性:

  • rotation: 旋转角度
  • translationX: X轴平移量
  • translationY: Y轴平移量
  • scaleX: X轴缩放比例
  • scaleY: Y轴缩放比例
  • alpha: 不透明度

属性动画的常用示例

以下是一些常用的属性动画示例:

  • 旋转动画
  • ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "rotation", 0f, 360f).setDuration(3000).start();
    1. 平移动画
    2. float curTranslationX = textview.getTranslationX();ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "translationX", curTranslationX, -500f, curTranslationX).setDuration(3000).start();
      1. 缩放动画
      2. ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "scaleY", 1f, 3f, 1f).setDuration(3000).start();

        注意事项

        • 动画时间:动画时间设定在setDuration方法中,单位为毫秒。
        • 自动回放:默认情况下,动画会自动回放,除非调用cancel()方法。
        • 多个属性同时动画:可以通过多次调用ofFloat方法,针对不同的属性进行同时动画。

        总结

        属性动画是Android开发中非常强大的工具,通过简单的代码可以实现丰富的视觉效果。通过合理使用ObjectAnimator类,可以轻松创建旋转、缩放、平移等动画效果。希望以上示例能为您提供帮助!

    转载地址:http://obac.baihongyu.com/

    你可能感兴趣的文章
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    no session found for current thread
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    no1
    查看>>
    NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
    查看>>
    NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    node exporter完整版
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>
    Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
    查看>>
    Node 裁切图片的方法
    查看>>
    Node+Express连接mysql实现增删改查
    查看>>
    node, nvm, npm,pnpm,以前简单的前端环境为什么越来越复杂
    查看>>