zoukankan      html  css  js  c++  java
  • 安卓AnimationDrawable之旋转动画

        在安卓开发中经常会看到旋转动画,这种动画效果有两种实现方式,一种是基于java代码,一种是在xml文件中定义,然后引用xml文件

      纯java代码实现:

    1      Animation animation = new RotateAnimation(0, 359);  
    2         animation.setDuration(500);  
    3         animation.setRepeatCount(8);//动画的重复次数  
    4         animation.setFillAfter(true);//设置为true,动画转化结束后被应用  
    5         imageView1.startAnimation(animation);//开始动画

      通过配置文件实现:

        在res文件下创建一个新的文件夹anim,这里的文件夹名字必须是anim,然后在anim中新建一个xml文件rotate(自定义),在这个xml文件中定义动画属性

     1 <set xmlns:android="http://schemas.android.com/apk/res/android">
     2 
     3     <rotate
     4         android:duration="5000"//旋转时间
     5         android:fromDegrees="0"//起始角度
     6         android:pivotX="50%"//起始点的x坐标
     7         android:pivotY="50%"//起始点的y坐标
     8         android:repeatCount="-1"//-1表示无限循环
     9         android:repeatMode="restart"//重复的模式,默认为restart,即重头开始重新运行,可以为reverse即从结束开始向前重新运行。在android:repeatCount大于0或为infinite时生效 
    10 android:toDegrees="360">//介绍时的角度 11 12 13 </rotate> 14 </set>
    在java代码中引用资源文件     

    ImageView green = (ImageView) findViewById(R.id.green); Animation rotate = AnimationUtils.loadAnimation(this,R.anim.rotate);//把资源文件放进Animation的对象中 green.startAnimation(rotate);

     

  • 相关阅读:
    Idea14 生成webservices
    第10组 Beta冲刺(4/4)
    2019 SDN上机第7次作业
    第10组 Beta冲刺(3/4)
    第10组 Beta冲刺(2/4)
    第10组 Beta冲刺(1/4)
    2019 SDN上机第6次作业
    SDN课程阅读作业(2)
    2019 SDN上机第5次作业
    第10组 Alpha冲刺(4/4)
  • 原文地址:https://www.cnblogs.com/lyd447113735/p/8026417.html
Copyright © 2011-2022 走看看