android定义animation动画效果
来源:互联网 发布:手机酷狗链接不到网络 编辑:程序博客网 时间:2024/05/22 17:13
方法一:在xml中定义动画:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Tween Animation:通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效
Alpha:渐变透明度动画效果
Scale:渐变尺寸伸缩动画效果
Translate:画面转换位置移动动画效果
Rotate:画面旋转动画效果
Tween Animation 通用属性[类型] 功能
Duration[long] 属性为动画持续时间 时间以毫秒为单位
fillAfter [boolean] 当设置为true ,该动画转化在动画结束后被应用
fillBefore[boolean] 当设置为true ,该动画转化在动画开始前被应用
interpolator 指定一个动画的插入器 有一些常见的插入器
accelerate_decelerate_interpolator
加速-减速 动画插入器
accelerate_interpolator
加速-动画插入器
decelerate_interpolator
减速- 动画插入器
其他的属于特定的动画效果
repeatCount[int] 动画的重复次数
RepeatMode[int] 定义重复的行为 1:重新开始 2:plays backward
startOffset[long] 动画之间的时间间隔,从上次动画停多少时间开始执行下个动画
zAdjustment[int] 定义动画的Z Order的改变 0:保持Z Order不变
1:保持在最上层
-1:保持在最下层
-->
<!--
透明控制动画
-->
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="3000"
/>
<!-- 尺寸伸缩动画效果 scale
属性:interpolator 指定一个动画的插入器
有三种动画插入器:
accelerate_decelerate_interpolator 加速-减速 动画插入器
accelerate_interpolator 加速-动画插入器
decelerate_interpolator 减速- 动画插入器
其他的属于特定的动画效果
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 ,该动画转化在动画结束后被应用
-->
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:repeatCount="1"
android:fromXScale="0.5"
android:fromYScale="0.5"
android:toXScale="1.4"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="3000"
/>
<!--
画面转换位置移动动画效果 translate
fromXDelta toXDelta 为动画、结束起始时 X坐标上的位置
fromYDelta toYDelta 为动画、结束起始时 Y坐标上的位置
-->
<translate
android:repeatCount="2"
android:fromXDelta="-30"
android:fromYDelta="-30"
android:toXDelta="-80"
android:toYDelta="200"
android:duration="3000"
/>
<!--
画面转移旋转动画效果 rotate
fromDegrees 为动画起始时物件的角度 说明
当角度为负数——表示逆时针旋转
当角度为正数——表示顺时针旋转
(负数from——to正数:顺时针旋转)
(负数from——to负数:逆时针旋转)
(正数from——to正数:顺时针旋转)
(正数from——to负数:逆时针旋转)
toDegrees 属性为动画结束时物件旋转的角度 可以大于360度
pivotX
pivotY 为动画相对于物件的X、Y坐标的开始位 说明:以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置
-->
<rotate
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="2"
android:fromDegrees="0"
android:toDegrees="+270"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"
/>
</set>
使用该xml动画到View上,如TextView
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.TextView;
public class TestAnimation extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.my_rotate_action);
findViewById(R.id.TextView01).startAnimation(anim);
}
}
方法二:直接在代码中定义动画(效果跟方法一类似):
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
public class TestAnimation extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.Button);
btn.setOnClickListener(this);
}
public void onClick(View v) {
Animation anim = null;
anim = new RotateAnimation(0.0f,+360.0f);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setDuration(3000);
findViewById(R.id.TextView01).startAnimation(anim);
}
}
- android定义animation动画效果
- Android animation 定义动画
- Android 动画效果 --Animation
- Android 动画效果 --Animation
- Android 动画效果 --Animation
- Android Animation动画效果
- android Animation 动画效果
- android Animation 动画效果
- Android 动画效果animation
- Android动画(Animation)效果
- android Animation动画效果
- Android - Animation动画效果
- Android:Animation动画效果
- android动画效果Animation
- 动画效果Animation-android
- android-Animation动画效果
- Android动画---Animation动画效果
- Android 动画效果 --Animation 动画
- 【设计模式】7. 模板方法模式 -封装算法
- 用byte array 声称的 Java String 对象的长度
- 改写《魔塔》前篇07:碰撞检测(附:前期阶段项目下载)
- 如何通过ssh来连接虚拟机(vmware)中的ubuntu
- KMeans聚类算法
- android定义animation动画效果
- FFmepg 多线程解码历程 - 5: ff_thread_init
- git install on Red Hat 5
- 浅谈C++中const成员和非const成员的联系和区别
- HTTP Live Streaming with a Webcam on Linux using VLC and a Segmenter
- ubuntu 快速部署openvpn
- SSH 登录ubuntu server在命令行中按tab键时总是提示LC_CTYPE 相关信息的解决办法
- 不由XML Layout 文件而由程序动态生成AlertDialog 及在其中附加更多UI 控件
- R.java 文件不能生成原因探究