浅谈Android中视图动画的属性与使用

浅谈Android中视图动画的属性与使用,第1张

概述简介Android动画主要包括视图动画和属性动画,视图动画包括Tween动画和Frame动画,Tween动画又包括渐变动画、平移动画、缩放动画、旋转动画。

简介

AndroID动画主要包括视图动画和属性动画,视图动画包括Tween动画和Frame动画,Tween动画又包括渐变动画、平移动画、缩放动画、旋转动画。

Tween动画的基本属性

      目标 VIEw;

      时常 duration;

      开始状态 fromXXX;

      结束动画 toXXX;

      开始时间 startOffset;

      重复次数 repeatCount;

      时间轴 interpolator(插值器)。

代码示例

xml实现

<?xml version="1.0" enCoding="utf-8"?> <translate xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:fromXDelta="0" androID:fromYDelta="0" androID:toXDelta="100%" androID:toYDelta="0" androID:fillAfter="true" androID:duration="3000"></translate>

在代码中调用

Animation translate = AnimationUtils.loadAnimation(context,R.anim.translate);imageVIEw.startAnimation(translate);

补充:

1.对于缩放和旋转动画,有一个pivotX或者pivotY,表示的是缩放或旋转的中心点。

对应的属性值有三种写法。

     ・ 数值 50 表示当前控件的左上角加上50px;

     ・ 百分数 50% 表示当前控件的50%;

     ・ 百分数p 50%p 表示父控件的50%。

2.在一个动画集合里,可以通过设置stratOffset属性,来实现多个动画并行和串行的效果。

Frame动画

Frame动画的配置文件放在drawable目录下

<?xml version="1.0" enCoding="utf-8"?><animation-List xmlns:androID="http://schemas.androID.com/apk/res/androID"> <item androID:drawable="@drawable/image1" androID:duration="50"/> <item androID:drawable="@drawable/image2" androID:duration="50"/> <item androID:drawable="@drawable/image3" androID:duration="50"/></animation-List>
// 需要先设置成背景imageVIEw.setBackgroundResource(R.drawable.frame_anim);AnimationDrawable frameAnimation = (AnimationDrawable) imageVIEw.getBackground();frameAnimation.start();

总结

以上就是这篇文章的全部内容了,希望本文的内容能对大家开发AndroID的时候有所帮助,如果有疑问大家可以留言交流。

总结

以上是内存溢出为你收集整理的浅谈Android中视图动画的属性与使用全部内容,希望文章能够帮你解决浅谈Android中视图动画的属性与使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1148102.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存