动画首页

作者: 压抑的内心 | 来源:发表于2018-04-13 12:00 被阅读33次

xml配置文件

    android:duration = "3000"

    android:fillAfter="true"

    android:fillBefore="false"

    android:fromAlpha="1.0"

    android:interpolator="@android:anim/linear_interpolator"

    android:repeatCount="-1"

    android:repeatMode="restart"

    android:startOffset="2000"

    android:toAlpha="0.3"/>

Java代码实现渐变

AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.2f);

        //设置动画持续时长        alphaAnimation.setDuration(3000);

        //设置动画结束之后的状态是否是动画的最终状态,true,表示是保持动画结束时的最终状态        alphaAnimation.setFillAfter(true);

        //设置动画结束之后的状态是否是动画开始时的状态,true,表示是保持动画开始时的状态        alphaAnimation.setFillBefore(true);

        //设置动画的重复模式:反转REVERSE和重新开始RESTART        alphaAnimation.setRepeatMode(AlphaAnimation.REVERSE);

        //设置动画播放次数        alphaAnimation.setRepeatCount(AlphaAnimation.INFINITE);

        //开始动画        mIvImg.startAnimation(alphaAnimation);

        //清除动画        mIvImg.clearAnimation();

        //同样cancel()也能取消掉动画        alphaAnimation.cancel();

//Java代码实现缩放

//创建缩放动画对象  

Animation animation =new ScaleAnimation(0, 1.0f, 0f, 1.0f);  

animation.setDuration(1500);//动画时间  

animation.setRepeatCount(3);//动画的重复次数  

animation.setFillAfter(true);//设置为true,动画转化结束后被应用  

imageView1.startAnimation(animation);//开始动画  

//  xml配置文件生成

android:duration="1500"  

android:fillAfter="true"  

android:fromXScale="0.0"  

android:fromYScale="0.0"  

android:interpolator="@android:anim/accelerate_decelerate_interpolator"  

android:pivotX="0%"  

android:pivotY="50%"  

android:toXScale="1.0"  

android:toYScale="1.0"  

/>  

旋转动画Java代码实现

//创建旋转动画   

Animation animation =new RotateAnimation(0, 359);  

animation.setDuration(500);  

animation.setRepeatCount(8);//动画的重复次数  

animation.setFillAfter(true);//设置为true,动画转化结束后被应用  

imageView1.startAnimation(animation);//开始动画  

xml配置文件实现

android:duration="1000"  

android:fromDegrees="0"  

android:toDegrees="+360"  

android:repeatCount="10"  

android:repeatMode="restart"  

android:pivotX="50%"  

android:pivotY="50%"  

android:interpolator="@android:anim/overshoot_interpolator"  

/>  

//xml配置文件实现

android:duration="500"  

android:fromYDelta="0%"  

android:toYDelta="100%" >        

android:duration="500"  

android:fromAlpha="0.0"  

android:interpolator="@android:anim/decelerate_interpolator"  

android:toAlpha="1.0" />  

//java 代码实现平移

TranslateAnimation animation =new TranslateAnimation(0.0f, 300.0f, 0.0f, 300.0f);  

animation.setDuration(3000);  

view.startAnimation(animation);  

相关文章

网友评论

    本文标题:动画首页

    本文链接:https://www.haomeiwen.com/subject/mgofqftx.html