android旋转动画的两种实现方式
在android開發(fā),我們會(huì)常常使用到旋轉(zhuǎn)動(dòng)畫,普通情況下旋轉(zhuǎn)動(dòng)畫有兩種實(shí)現(xiàn)方式,一種是直接通過java代碼去實(shí)現(xiàn),第二種是通過配置文件實(shí)現(xiàn)動(dòng)畫。以下是兩種動(dòng)畫的基本是用法:
純Java代碼實(shí)現(xiàn):
//創(chuàng)建旋轉(zhuǎn)動(dòng)畫 Animation animation = new RotateAnimation(0, 359);animation.setDuration(500);animation.setRepeatCount(8);//動(dòng)畫的反復(fù)次數(shù)animation.setFillAfter(true);//設(shè)置為true,動(dòng)畫轉(zhuǎn)化結(jié)束后被應(yīng)用imageView1.startAnimation(animation);//開始動(dòng)畫
通過配置文件實(shí)現(xiàn):
1、首先要在res文件夾下建立一個(gè)anim文件,在anim建立一個(gè)rotate.xml文件例如以下:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate 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" /> </set>
2、載入動(dòng)畫
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);imageView1.startAnimation(animation);//開始動(dòng)畫
案例下載地址:http://download.csdn.net/detail/u013043346/9374204
轉(zhuǎn)載于:https://www.cnblogs.com/llguanli/p/8674274.html
總結(jié)
以上是生活随笔為你收集整理的android旋转动画的两种实现方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 财务分析报表APP的功能优势
- 下一篇: 近距离无线通信技术对比