源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-05-21 09:16 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:浅谈Android中视图动画的属性与使用
[b]简介[/b] Android动画主要包括视图动画和属性动画,视图动画包括Tween动画和Frame动画,Tween动画又包括渐变动画、平移动画、缩放动画、旋转动画。 [b]Tween动画的基本属性[/b]       目标 View;       时常 duration;       开始状态 fromXXX;       结束动画 toXXX;       开始时间 startOffset;       重复次数 repeatCount;       时间轴 interpolator(插值器)。 [b]代码示例[/b] [b]xml实现[/b]
<?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>
[b]在代码中调用[/b]
Animation translate = AnimationUtils.loadAnimation(context,R.anim.translate);
imageView.startAnimation(translate);
[b]补充:[/b] 1.对于缩放和旋转动画,有一个[code]pivotX[/code]或者[code]pivotY[/code],表示的是缩放或旋转的中心点。 [b]对应的属性值有三种写法。[/b]      · 数值 50 表示当前控件的左上角加上50px;      · 百分数 50% 表示当前控件的50%;      · 百分数p 50%p 表示父控件的50%。 2.在一个动画集合里,可以通过设置[code]stratOffset[/code]属性,来实现多个动画并行和串行的效果。 [b]Frame动画[/b] 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();
[b]总结[/b] 以上就是这篇文章的全部内容了,希望本文的内容能对大家开发Android的时候有所帮助,如果有疑问大家可以留言交流。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部