Android控件动画
2015-11-07 12:20
495 查看
圆周轨迹动画:
<span style="font-size:18px;"> protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView image = (ImageView) this.findViewById(R.id.image);
Button btn = (Button) this.findViewById(R.id.btn);
final ValueAnimator animator = ValueAnimator.ofFloat(0, 360);
animator.setDuration(1500);
animator.setInterpolator(new LinearInterpolator());
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator anim) {
float i = (Float) anim.getAnimatedValue();
image.setX(-(1 - i / 360) * 100
* (float) Math.sin(i * Math.PI / 180));
image.setY(-(1 - i / 360) * 100
* (float) Math.cos(i * Math.PI / 180));
image.setAlpha(i);
// image.setScaleX(i);
// image.setScaleY(i);
}
});
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// image.startAnimation(rotate);
animator.cancel();
animator.start();
}
});
}
}
</span>
2 浮标动画:
<span style="font-size:18px;">package com.example.animation;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.graphics.PointF;
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.view.animation.CycleInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView image = (ImageView) this.findViewById(R.id.image);
final Button btn = (Button) this.findViewById(R.id.btn);
//加载anim文件 的xml
final Animation animation=AnimationUtils.
loadAnimation(this, R.anim.tween_animation);
animation.setDuration(2000);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// image.startAnimation(rotate);
image.startAnimation(animation);
}
});
}
}
</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1000" android:fromXDelta="0" android:fromYDelta="-15" android:repeatCount="infinite" android:toXDelta="0" android:toYDelta="20" /> <alpha android:duration="1000" android:fromAlpha="1.0" android:repeatCount="infinite" android:toAlpha="0.3" /> </set></span>
3 组合动画 旋转
<span style="font-size:18px;"><set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="800"
android:fillAfter="false"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2" />
<rotate
android:duration="3000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="-1"
android:toDegrees="359.0" />
</set> </span>4 摇摆动画
<span style="font-size:18px;"> int pivot = Animation.RELATIVE_TO_SELF;
CycleInterpolator interpolator = new CycleInterpolator(3.0f);
final RotateAnimation animation = new RotateAnimation(0, 10, pivot,
0.47f, pivot, 0.05f);
animation.setStartOffset(500);
animation.setDuration(3000);
animation.setRepeatCount(1);// Animation.INFINITE
animation.setInterpolator(interpolator); </span>
5 一个角度摇摆
RELATIVE_TO_PARENT <span style="font-size:18px;">int pivot=RELATIVE_TO_PARENT 换成这个参数</span>
相关文章推荐
- win2003服务器/虚拟主机不支持Flv和ANI格式文件的解决方案
- Android 动画之AlphaAnimation应用详解
- Android实现动画效果详解
- Android动画之3D翻转效果实现函数分析
- BaseAnimation是基于开源的APP,致力于收集各种动画效果(最新版本1.2)
- 关于TranslateAnimation()的参数问题
- Android的屏幕切换动画
- Android动画之Drawable Animation
- Drawable Animation
- Property Animation
- 收集android上开源的酷炫的交互动画和视觉效果
- 动画的简单介绍
- Interpolator的几种属性
- Android动画之Tween动画实现
- Android Animation动画详解(一): 补间动画
- Android Animation动画实战(一): 从布局动画引入ListView滑动时,每一Item项的显示动画
- Android Animation动画实战(二):从屏幕底部弹出PopupWindow
- Android开发之视图动画基础
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
- 【Android动画】之Frame动画