Android动画分为四种:alpha(渐变透明度),scale(渐变尺寸伸缩),translate(画面转换位置移动),rotate(画面转移旋转)
停止动画
tvTrynow.clearAnimation();
画面转换位置移动
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true"> <translate android:duration="900" android:fromXDelta="0" android:fromYDelta="0" android:repeatCount="200" android:toXDelta="0" android:toYDelta="50%" /> </set>
渐变透明度
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.2" android:toAlpha="1.0" android:duration="1500" /> </set>
动画效果从XMl文件中引用
Animation animation = AnimationUtils.loadAnimation(this, R.anim.set_alpha); tvTrynow.setAnimation(animation);
动画效果直接定义
Animation animation = new AlphaAnimation(0.2f, 1.0f); animation.setDuration(1500); tvTrynow.setAnimation(animation);
动画监听
animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { startAct(HomeActivity.class); finish(); } });