android縮放動畫的兩種實現方法
阿新 • • 發佈:2017-06-17
get odi omx rac tor Coding eight rpo odin
通過配置文件實現:
2、載入動畫:
在android開發。我們會常常使用到縮放動畫,普通情況下縮放動畫有兩種實現方式。一種是直接通過java代碼去實現,第二種是通過配置文件實現動畫,以下是兩種動畫的基本是用法:
Java代碼實現:
//創建縮放動畫對象 Animation animation = new ScaleAnimation(0, 1.0f, 0f, 1.0f); animation.setDuration(1500);//動畫時間 animation.setRepeatCount(3);//動畫的反復次數 animation.setFillAfter(true);//設置為true,動畫轉化結束後被應用 imageView1.startAnimation(animation);//開始動畫
通過配置文件實現:
1、首先要在res文件夾下建立一個anim文件,在anim建立一個scale.xml文件例如以下:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale 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" /> </set>
2、載入動畫:
Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale); imageView1.startAnimation(animation);//開始動畫案例下載地址:http://download.csdn.net/detail/u013043346/9374204
android縮放動畫的兩種實現方法