android 設定透明動畫

首先在res/anin創建檔案


1.
fadein.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:fillAfter="true"
android:duration="200"/>
fadeout.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:fillAfter="true"
android:duration="200"/>
view raw alpha.xml hosted with ❤ by GitHub



在main activity裡面建立
2.
private void fadeoutXml(){
Animation animation= AnimationUtils.loadAnimation(this,
R.anim.alpha_fadeout);
imageView.startAnimation(animation);
}
private void fadeinXml(){
Animation animation= AnimationUtils.loadAnimation(this,
R.anim.alpha_fadein);
imageView.startAnimation(animation);
}
view raw animator.java hosted with ❤ by GitHub

留言

這個網誌中的熱門文章

android service作法

html css & bootstrap心得