透明度动画、旋转动画、尺寸伸缩动画、移动动画参数详解
2013-07-31 11:07
537 查看
Animation 动画:
定义
[java]
private Animation animation_alpha,animation_scale,animation_translate,animation_rotate;
private AnimationSet animationSet;
分别是透明度动画、旋转动画、尺寸伸缩动画、移动动画
具体实现代码如下:
[java]
private void initAnimation() {
//透明度控制动画效果 alpha
animation_alpha=new AlphaAnimation(0.1f,1.0f);
//第一个参数fromAlpha为 动画开始时候透明度
//第二个参数toAlpha为 动画结束时候透明度
animation_alpha.setRepeatCount(-1);//设置循环
animation_alpha.setDuration(5000);//设置时间持续时间为 5000毫秒
// 旋转效果rotate
animation_rotate = new RotateAnimation(0, -720,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
//第一个参数fromDegrees为动画起始时的旋转角度 //第二个参数toDegrees为动画旋转到的角度
//第三个参数pivotXType为动画在X轴相对于物件位置类型 //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第五个参数pivotXType为动画在Y轴相对于物件位置类型 //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_rotate.setRepeatCount(-1);
animation_rotate.setDuration(5000);//设置时间持续时间为 5000毫秒
//尺寸伸缩动画效果 scale
animation_scale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸
//第二个参数toX为动画结束时 X坐标上的伸缩尺寸
//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸
//第四个参数toY为动画结束时Y坐标上的伸缩尺寸
/*说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
*/
//第五个参数pivotXType为动画在X轴相对于物件位置类型
//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第七个参数pivotXType为动画在Y轴相对于物件位置类型
//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_scale.setRepeatCount(-1);
animation_scale.setDuration(5000);//设置时间持续时间为 5000毫秒
//移动动画效果translate
animation_translate=new TranslateAnimation(-20f,300f,-20f,300f);
//第一个参数fromXDelta为动画起始时 X坐标上的移动位置
//第二个参数toXDelta为动画结束时 X坐标上的移动位置
//第三个参数fromYDelta为动画起始时Y坐标上的移动位置
//第三个参数toYDelta为动画结束时Y坐标上的移动位置
animation_translate.setRepeatCount(-1);//设置动画执行多少次,如果是-1的话就是一直重复
animation_translate.setDuration(5000);//设置时间持续时间为 5000毫秒
animationSet=new AnimationSet(true);
animationSet.addAnimation(animation_alpha);//透明度
animationSet.addAnimation(animation_rotate);//旋转
animationSet.addAnimation(animation_scale);//尺寸伸缩
animationSet.addAnimation(animation_translate);//移动
image.startAnimation(animationSet);//开始播放
}
原文:http://www.linuxidc.com/Linux/2012-01/51450.htm
1、Android 平台提供了两类动画,一类是 Tween 动画,即通过对场景里的对象不断做图像变换 ( 平移、缩放、旋转 ) 产生动画效果;第二类是 Frame 动画,即顺序播放事先做好的图像,跟电影类似。我们先介绍Tween来实现简单的动画;
2、首先看效果图
在项目res文件夹下建一个anim文件夹里建一个tween.xml文件:
[html]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="5000"
android:fromAlpha="0"
android:toAlpha="1.0" />
<!--
透明度控制动画效果 alpha
浮点型值:
fromAlpha 属性为动画起始时透明度
toAlpha 属性为动画结束时透明度
说明:
0.0表示完全透明
1.0表示完全不透明
以上值取0.0-1.0之间的float数据类型的数字
长整型值:
duration 属性为动画持续时间
说明:
时间以毫秒为单位
-->
<rotate
android:duration="5000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="1080" />
<!--
rotate 旋转动画效果
浮点数型值:
fromDegrees 属性为动画起始时物件的角度
toDegrees 属性为动画结束时物件旋转的角度 可以大于360度
说明:
当角度为负数——表示逆时针旋转
当角度为正数——表示顺时针旋转
(负数from——to正数:顺时针旋转)
(负数from——to负数:逆时针旋转)
(正数from——to正数:顺时针旋转)
(正数from——to负数:逆时针旋转)
pivotX 属性为动画相对于物件的X坐标的开始位置
pivotY 属性为动画相对于物件的Y坐标的开始位置
说明: 以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
-->
<scale
android:duration="5000"
android:fromXScale="0.1"
android:fromYScale="0.1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3.0"
android:toYScale="3.0" />
<!--
尺寸伸缩动画效果 scale
浮点型值:
fromXScale 属性为动画起始时 X坐标上的伸缩尺寸
toXScale 属性为动画结束时 X坐标上的伸缩尺寸
fromYScale 属性为动画起始时Y坐标上的伸缩尺寸
toYScale 属性为动画结束时Y坐标上的伸缩尺寸
说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
pivotX 属性为动画相对于物件的X坐标的开始位置
pivotY 属性为动画相对于物件的Y坐标的开始位置
说明:
以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
布尔型值:
fillAfter 属性 当设置为true ,该动画转化在动画结束后被应用
-->
<translate
android:duration="5000"
android:fromXDelta="-20"
android:fromYDelta="-20"
android:toXDelta="300"
android:toYDelta="300" />
<!--
translate 位置转移动画效果
整型值:
fromXDelta 属性为动画起始时 X坐标上的位置
toXDelta 属性为动画结束时 X坐标上的位置
fromYDelta 属性为动画起始时 Y坐标上的位置
toYDelta 属性为动画结束时 Y坐标上的位置
注意:
没有指定fromXType toXType fromYType toYType 时候,
默认是以自己为相对参照物
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
-->
</set>
Android的animation由四种类型组成
在main.xml文件中定义一个按钮和一个ImageView:
[html]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="重播"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/pic"
android:id="@+id/image"/>
</LinearLayout>
button按钮用来重播,imageView用来显示那个动画效果的!
最后是java代码,MyAnimation.java:
[java]
package cn.csdn.anim;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MyAnimation extends Activity implements OnClickListener {
private ImageView image = null;
private Button button = null;
private Animation animation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init() {
image = (ImageView) this.findViewById(R.id.image);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
animation = AnimationUtils.loadAnimation(this, R.anim.tween);// 使用AnimationUtils类的静态方法loadAnimation()来加载XML中的动画XML文件
image.startAnimation(animation);// 开始动画播出
}
@Override
public void onClick(View v) {
image.startAnimation(animation);// 开始动画播出
}
}
是不是很简单!!
原文:http://www.linuxidc.com/Linux/2012-01/51449.htm
定义
[java]
private Animation animation_alpha,animation_scale,animation_translate,animation_rotate;
private AnimationSet animationSet;
分别是透明度动画、旋转动画、尺寸伸缩动画、移动动画
具体实现代码如下:
[java]
private void initAnimation() {
//透明度控制动画效果 alpha
animation_alpha=new AlphaAnimation(0.1f,1.0f);
//第一个参数fromAlpha为 动画开始时候透明度
//第二个参数toAlpha为 动画结束时候透明度
animation_alpha.setRepeatCount(-1);//设置循环
animation_alpha.setDuration(5000);//设置时间持续时间为 5000毫秒
// 旋转效果rotate
animation_rotate = new RotateAnimation(0, -720,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
//第一个参数fromDegrees为动画起始时的旋转角度 //第二个参数toDegrees为动画旋转到的角度
//第三个参数pivotXType为动画在X轴相对于物件位置类型 //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第五个参数pivotXType为动画在Y轴相对于物件位置类型 //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_rotate.setRepeatCount(-1);
animation_rotate.setDuration(5000);//设置时间持续时间为 5000毫秒
//尺寸伸缩动画效果 scale
animation_scale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸
//第二个参数toX为动画结束时 X坐标上的伸缩尺寸
//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸
//第四个参数toY为动画结束时Y坐标上的伸缩尺寸
/*说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
*/
//第五个参数pivotXType为动画在X轴相对于物件位置类型
//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第七个参数pivotXType为动画在Y轴相对于物件位置类型
//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_scale.setRepeatCount(-1);
animation_scale.setDuration(5000);//设置时间持续时间为 5000毫秒
//移动动画效果translate
animation_translate=new TranslateAnimation(-20f,300f,-20f,300f);
//第一个参数fromXDelta为动画起始时 X坐标上的移动位置
//第二个参数toXDelta为动画结束时 X坐标上的移动位置
//第三个参数fromYDelta为动画起始时Y坐标上的移动位置
//第三个参数toYDelta为动画结束时Y坐标上的移动位置
animation_translate.setRepeatCount(-1);//设置动画执行多少次,如果是-1的话就是一直重复
animation_translate.setDuration(5000);//设置时间持续时间为 5000毫秒
animationSet=new AnimationSet(true);
animationSet.addAnimation(animation_alpha);//透明度
animationSet.addAnimation(animation_rotate);//旋转
animationSet.addAnimation(animation_scale);//尺寸伸缩
animationSet.addAnimation(animation_translate);//移动
image.startAnimation(animationSet);//开始播放
}
原文:http://www.linuxidc.com/Linux/2012-01/51450.htm
1、Android 平台提供了两类动画,一类是 Tween 动画,即通过对场景里的对象不断做图像变换 ( 平移、缩放、旋转 ) 产生动画效果;第二类是 Frame 动画,即顺序播放事先做好的图像,跟电影类似。我们先介绍Tween来实现简单的动画;
2、首先看效果图
在项目res文件夹下建一个anim文件夹里建一个tween.xml文件:
[html]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="5000"
android:fromAlpha="0"
android:toAlpha="1.0" />
<!--
透明度控制动画效果 alpha
浮点型值:
fromAlpha 属性为动画起始时透明度
toAlpha 属性为动画结束时透明度
说明:
0.0表示完全透明
1.0表示完全不透明
以上值取0.0-1.0之间的float数据类型的数字
长整型值:
duration 属性为动画持续时间
说明:
时间以毫秒为单位
-->
<rotate
android:duration="5000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="1080" />
<!--
rotate 旋转动画效果
浮点数型值:
fromDegrees 属性为动画起始时物件的角度
toDegrees 属性为动画结束时物件旋转的角度 可以大于360度
说明:
当角度为负数——表示逆时针旋转
当角度为正数——表示顺时针旋转
(负数from——to正数:顺时针旋转)
(负数from——to负数:逆时针旋转)
(正数from——to正数:顺时针旋转)
(正数from——to负数:逆时针旋转)
pivotX 属性为动画相对于物件的X坐标的开始位置
pivotY 属性为动画相对于物件的Y坐标的开始位置
说明: 以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
-->
<scale
android:duration="5000"
android:fromXScale="0.1"
android:fromYScale="0.1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3.0"
android:toYScale="3.0" />
<!--
尺寸伸缩动画效果 scale
浮点型值:
fromXScale 属性为动画起始时 X坐标上的伸缩尺寸
toXScale 属性为动画结束时 X坐标上的伸缩尺寸
fromYScale 属性为动画起始时Y坐标上的伸缩尺寸
toYScale 属性为动画结束时Y坐标上的伸缩尺寸
说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
pivotX 属性为动画相对于物件的X坐标的开始位置
pivotY 属性为动画相对于物件的Y坐标的开始位置
说明:
以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
布尔型值:
fillAfter 属性 当设置为true ,该动画转化在动画结束后被应用
-->
<translate
android:duration="5000"
android:fromXDelta="-20"
android:fromYDelta="-20"
android:toXDelta="300"
android:toYDelta="300" />
<!--
translate 位置转移动画效果
整型值:
fromXDelta 属性为动画起始时 X坐标上的位置
toXDelta 属性为动画结束时 X坐标上的位置
fromYDelta 属性为动画起始时 Y坐标上的位置
toYDelta 属性为动画结束时 Y坐标上的位置
注意:
没有指定fromXType toXType fromYType toYType 时候,
默认是以自己为相对参照物
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
-->
</set>
Android的animation由四种类型组成
alpha | 渐变透明度动画效果 |
scale | 渐变尺寸伸缩动画效果 |
translate | 画面转换位置移动动画效果 |
rotate | 画面转移旋转动画效果 |
[html]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="重播"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/pic"
android:id="@+id/image"/>
</LinearLayout>
button按钮用来重播,imageView用来显示那个动画效果的!
最后是java代码,MyAnimation.java:
[java]
package cn.csdn.anim;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MyAnimation extends Activity implements OnClickListener {
private ImageView image = null;
private Button button = null;
private Animation animation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init() {
image = (ImageView) this.findViewById(R.id.image);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
animation = AnimationUtils.loadAnimation(this, R.anim.tween);// 使用AnimationUtils类的静态方法loadAnimation()来加载XML中的动画XML文件
image.startAnimation(animation);// 开始动画播出
}
@Override
public void onClick(View v) {
image.startAnimation(animation);// 开始动画播出
}
}
是不是很简单!!
alpha | 渐变透明度动画效果 |
scale | 渐变尺寸伸缩动画效果 |
translate | 画面转换位置移动动画效果 |
rotate | 画面转移旋转动画效果 |
相关文章推荐
- 动画效果:位置移动、画面旋转、渐变透明度、渐变尺寸缩放
- 安卓中为View添加动画效果(尺寸缩放、透明度渐变、旋转、移动)
- Android基础-简单的动画实现 *补间动画 *透明度渐变 *旋转动画 *位移动画 *如果需要几个效果整合到一起,需要将所有效果全部放到set里
- IOS 简单的动画自定义方法(旋转、移动、闪烁等)
- openGL点精灵PointSprite详解: 纹理映射,旋转,缩放,移动
- 移动web中设计尺寸与制作尺寸详解
- javascript动画-鼠标移动到时透明度渐变
- 手势检测实现相册的左右滑动(并加上移动与旋转的特效) 首先,activity_main.xml里,使用ViewFlipper组件(可使用动画控制多个组件之间的切换效果) <?xml version="
- Unity开发详解之旋转、移动、碰撞(3/6)
- 【iphone游戏开发】iphone-Cocos2d游戏开发之四:精灵实现缩放,旋转,跳动,移动等动画
- Android模仿iPhone View旋转刷新数据动画详解 推荐
- IOS--CALayer实现,界限、透明度、位置、旋转、缩放组合动画(转)
- Android 通过Animate硬编码实现简单的平移、旋转、缩放及透明度动画过程
- 【Android开发】动画范例2-旋转、平移、缩放和透明度渐变的补间动画
- CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)
- TweenedAnimation 四种动画效果参数详解
- android旋转动画和平移动画详解,补充说一下如果制作gif动画放到csdn博客上
- Android模仿iPhone View旋转刷新数据动画详解
- 动画制作之旋转案例:平移transform;过度样式transition;透明度opacity;旋转:rotate()
- 动画 (不停旋转 | 由内向外扩大缩小 透明度渐变)