读书人

android中的animations的用法 (1)

发布时间: 2012-07-20 10:38:30 作者: rapoo

android中的animations的用法 (一)
Animations 可分为两大类:

一 Tweened Animations,该类Animations提供了旋转,移动,伸展,和淡入淡出等效果

二 Frame-by-Frame Animations ,该类Animations 可以创建一个Drawable序列,这些Drawable可能按照指定的时间一个一个的显示,类似于电影.

Tweened Animations 有这4种分类

1 Alpha 淡入淡出

2 Rotate 旋转

3 Scale 缩放

4 Translate 移动

使用Tweened Animations 的步骤

1. 创建一个Animations 对象

2. 根据需要创建相应的Animation对象

3. 按照需求,为Animation 对象设置相应的数据

4. 将Animation对象添加到AnimationSet对象当中

5. 使用控件对象开始执行AnimationSet

各种Animation 的主要属性

Animation type | attributes | valid values

Alpha fromAlpha/toAlpha Float from 0 to 1

Scale fromXScale/toXScale Float from 0 to 1

fromYScale/toYScale Float from 0 to 1

pivotX/pivotY String of the percentage of graphic

width/height from 0% to 100%

Translate fromX/to X Float from 0 to 1

from Y/to Y Float from 0 to 1

Rotate fromDegrees/toDegrees Float from 0 to 360

pivotX/pivotY String of the percentage of graphic

width/height from 0% to 100%

---------------------------

layout布局文件mian.xml文件


activity文件:

</set>

3. 在该标签当中加入rotate,alpha,scale,translate标签

4. 在代码当中使用AnimationUtils当中装载xml文件,并生成 Animation 对象

在rotate.xml文件中

android:pivotX的值共有三种设置方法:

1. android:pivotX="50" 使用绝对位置定位

2. android:pivotX="50%" 使用相对于控件本身定位

3. android:pivotX="50%p" 使用相对于控件的父控件定位



读书人网 >Android

热点推荐