- import android.view.View;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.view.animation.Animation.AnimationListener;
- import android.view.animation.AnimationSet;
- import android.view.animation.LinearInterpolator;
- import android.view.animation.RotateAnimation;
- import android.view.animation.ScaleAnimation;
- import android.view.animation.TranslateAnimation;
-
- public class AnimationEffect
- {
- public static void AddAlphaAni(View view)
- {
- AddAlphaAni(view, 0, 1, 1000, Animation.REVERSE, Animation.INFINITE);
- }
- public static void AddAlphaAni(View view, float fromAlpha, float toAlpha, long durationMillis, int repeatMode, int repeatCount)
- {
- AlphaAnimation alphaAni = new AlphaAnimation(fromAlpha, toAlpha);
- alphaAni.setDuration(durationMillis);
- alphaAni.setRepeatMode(repeatMode);
- alphaAni.setRepeatCount(repeatCount);
- view.startAnimation(alphaAni);
- }
- public static void setTransAni(View view, int x0, int x1, int y0, int y1, long durationMillis)
- {
- TranslateAnimation transAni = new TranslateAnimation(x0, x1, y0, y1);
- transAni.setDuration(durationMillis);
- transAni.setRepeatMode(Animation.REVERSE);
- transAni.setRepeatCount(Animation.INFINITE);
- view.startAnimation(transAni);
- }
- public static void setRotateAni(View view, float fromDegrees, float toDegrees, long time)
- {
- setRotateAni(view, fromDegrees, toDegrees, time, Animation.REVERSE, Animation.INFINITE, true);
- }
- public static void setRotateAni(View view, float fromDegrees, float toDegrees, long durationMillis, int repeatModes, int repeatCount, boolean linear)
- {
- RotateAnimation rotateAni = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- rotateAni.setDuration(durationMillis);
- rotateAni.setRepeatMode(repeatModes);
- rotateAni.setRepeatCount(repeatCount);
- if(linear) rotateAni.setInterpolator(new LinearInterpolator());
- view.startAnimation(rotateAni);
- }
- public static void setScaleAni(View V, float fromScale, float toScale, long ANITIME)
- {
- AnimationSet aniSet = new AnimationSet(true);
- ScaleAnimation scaleAni = new ScaleAnimation(fromScale, toScale, fromScale, toScale, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- scaleAni.setDuration(ANITIME);
- aniSet.addAnimation(scaleAni);
- V.startAnimation(aniSet);
- }
- public static void setLightExpendAni(View V)
- {
- AnimationSet aniSet = new AnimationSet(true);
- final int ANITIME = 1200;
- /
- ScaleAnimation scaleAni = new ScaleAnimation(0.98f, 1.1f, 0.98f, 1.24f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- scaleAni.setDuration(ANITIME);
- scaleAni.setRepeatMode(Animation.RESTART);
- scaleAni.setRepeatCount(Animation.INFINITE);
- aniSet.addAnimation(scaleAni);
- AlphaAnimation alphaAni = new AlphaAnimation(1f, 0.05f);
- alphaAni.setDuration(ANITIME);
- alphaAni.setRepeatMode(Animation.RESTART);
- alphaAni.setRepeatCount(Animation.INFINITE);
- aniSet.addAnimation(alphaAni);
- V.startAnimation(aniSet);
- }
- public static void setLightAni(final View view)
- {
- AnimationListener listenser = new AnimationListener()
- {
- @Override
- public void onAnimationEnd(Animation animation)
- {
- view.clearAnimation();
- setRotateAni(view, 36, 3996, 110000, Animation.RESTART, Animation.INFINITE, true);
- }
- @Override
- public void onAnimationRepeat(Animation animation)
- {}
- @Override
- public void onAnimationStart(Animation animation)
- {}
- };
- AnimationSet set = new AnimationSet(true);
- AlphaAnimation alphaAni = new AlphaAnimation(0.0f, 1f);
- alphaAni.setDuration(1000);
- set.addAnimation(alphaAni);
- RotateAnimation rotateAni = new RotateAnimation(0, 36, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- rotateAni.setDuration(1000);
- set.addAnimation(rotateAni);
- ScaleAnimation scaleAni = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- scaleAni.setDuration(1000);
- scaleAni.setAnimationListener(listenser);
- set.addAnimation(scaleAni);
- view.startAnimation(set);
- }
- }
view
最新推荐文章于 2022-03-14 14:09:55 发布