当前位置: 移动技术网 > IT编程>移动开发>Android > 浅谈Android中视图动画的属性与使用

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

刷钻平台,金瓶梅快播在线观看,笨笨卡盟

简介

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的时候有所帮助,如果有疑问大家可以留言交流。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网