創建資源文件:
在res目錄下創建anim文件夾,在anim文件夾下新建一個資源文件,文件名隨意
編寫代碼
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1"
android:toAlpha="0.5"
android:duration="30"
android:repeatCount="1000" />
屬性介紹
android:fromAlpha 動畫開始時的透明度
android:toAlpha 動畫結束時的透明度
android:duration 每次動畫持續時間
android:repeatCount 動畫重複次數
初始化動畫
imageView = (ImageView) rootView.findViewById(R.id.imageview);
animation = AnimationUtils.loadAnimation(getContext(), R.anim.alpha);
開始動畫
imageView.startAnimation(animation);
結束動畫
animation.cancel();