Android動畫——Tween動畫之Alpha

創建資源文件:

在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();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章