1===============<alpha/>========淡入淡出=====================
1、先看配置文件
当只有一个<alpha>标签是,动画执行一次
<alpha
android:duration="3000" ---动画的动作过程执行时间为3000毫秒 android:fromAlpha="0.0" ---从0%透明开始(完全透明) android:toAlpha="1.0" />---从100%透明结束(原图) />
<alpha
android:duration="3000" ---动画的动作过程执行时间为3000毫秒 android:fromAlpha="1.0" ---从100%透明开始(原图) android:toAlpha="0.0" ---从0%透明结束(完全透明)
android:startOffset="3000" ---当第一次动画执行3000毫秒之后再开始/>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" android:fillBefore="false" android:interpolator="@android:anim/accelerate_interpolator" > <alpha android:duration="3000" android:fromAlpha="0.0" android:toAlpha="1.0" /> <alpha android:duration="3000" android:fromAlpha="1.0" android:startOffset="3000" android:toAlpha="0.0" /> </set>
java代码实现
AnimationSet animationSet = new AnimationSet(true); AlphaAnimation alphaAnimation1 = new AlphaAnimation(0, 1); alphaAnimation.setDuration(3000); animationSet.addAnimation(alphaAnimation1);
AlphaAnimation alphaAnimation2 = new AlphaAnimation(1, 0); alphaAnimation.setDuration(3000);
alphaAnimation.setStartOffset(3000);
animationSet.addAnimation(alphaAnimation2);
animationSet.setFillBefore(false); animationSet.setFillAfter(true);
2=============<scale/>===========放大放小===========
XML文件
<scale android:duration="6000" /*动画时间*/ android:fromXScale="0.0" /*开始width的比例*/ android:fromYScale="0.0" /*开始hight的比例*/ android:pivotX="50%" /*X坐标相对分辨率X的比率*/ android:pivotY="50%" /*Y坐标相对分辨率Y的比率*/ android:toXScale="1.0" /*结束时width的比例*/ android:toYScale="1.0" /> /*结束是hight的比例*/ <scale android:duration="6000" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="6000" android:toXScale="0.0" android:toYScale="0.0" />
java 代码实现
AnimationSet animationSet = new AnimationSet(true); ScaleAnimation scaleAnimation1 = new ScaleAnimation(0.0f, 1, 0.0f, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animationSet.addAnimation(scaleAnimation1);
scaleAnimation1.setDuration(6000);
ScaleAnimation scaleAnimation2 = new ScaleAnimation(1, 0.0f, 1, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animationSet.addAnimation(scaleAnimation2);
scaleAnimation2.setDuration(6000);
scaleAnimation2.setStartOffset(6000);
3=================<Rotate/>=======正顺旋转效果===============
XML文件
<rotate android:duration="3000" /*动画时间*/ android:fromDegrees="0" /*从0度开始*/ android:pivotX="50%" /*中心的X坐标*/ android:pivotY="50%" /*中心的Y坐标*/ android:toDegrees="+360" /> /*顺时针旋转360度*/ <rotate android:duration="3000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:startOffset="3000" android:toDegrees="-360" /> /*逆时针旋转360度*/
Java代码实现
AnimationSet animationSet = new AnimationSet(true); RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f); rotateAnimation1.setDuration(3000); animationSet.addAnimation(rotateAnimation1); RotateAnimation rotateAnimation2 = new RotateAnimation(0, 360, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f); rotateAnimation2.setDuration(3000); animationSet.addAnimation(rotateAnimation2); rotateAnimation2.setStartOffset(3000);
4================<Translate/>========移来移去效果==========
<translate android:fromXDelta="0%p" /*X坐标的在初始*/ android:toXDelta="100%p" /*X坐标向右移出屏幕(-100%p为向左移出屏幕)*/ android:fromYDelta="0%p" /*Y在初始*/ android:toYDelta="100%p" /*Y移除屏幕(-100%p为向下移出屏幕)*/ android:duration="3000" /> /**/
java 实现代码
AnimationSet animationSet = new AnimationSet(true); TranslateAnimation translateAnimation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1.0f); translateAnimation.setDuration(1000); animationSet.addAnimation(translateAnimation);
end>>>>>>>>java调用代码
ImageView imageView=(ImageView)findViewById(R.id.imag1); imageView.setImageResource(R.drawable.pc1); //实现淡入淡出 Animation animation = AnimationUtils.loadAnimation(LeastinputActivity.this, R.anim.leastinout); imageView.startAnimation(animation);