图片的淡入淡出效果实现

 

还算简单,先发个图看看效果。

 

主文件:

  1. import android.app.Activity;  
  2. import android.os.Bundle;  
  3. import android.view.animation.AnimationUtils;  
  4. import android.widget.ViewFlipper;  
  5.   
  6. public class TextAnimationActivity extends Activity {  
  7.     /** Called when the activity is first created. */  
  8.     @Override  
  9.     public void onCreate(Bundle savedInstanceState) {  
  10.         super.onCreate(savedInstanceState);  
  11.         setContentView(R.layout.main);  
  12.         ViewFlipper viewFilpper = (ViewFlipper) findViewById(R.id.flipper);  
  13.         viewFilpper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_in));  
  14.         viewFilpper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_out));  
  15.         viewFilpper.startFlipping();  
  16.     }  
  17. }  

anim文件:

push_in.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <set xmlns:android="http://schemas.android.com/apk/res/android">  
  4.       
  5.     <translate android:fromYDelta="100"   
  6.                android:toYDelta="0"   
  7.                android:duration="3000"/>  
  8.                  
  9.     <alpha android:fromAlpha="0.0"   
  10.            android:toAlpha="1.0"   
  11.            android:duration="3000" />  
  12. </set>  


push_out.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <set xmlns:android="http://schemas.android.com/apk/res/android">  
  4.       
  5.     <translate android:fromYDelta="0"   
  6.                android:toYDelta="-100"   
  7.                android:duration="500"/>  
  8.                  
  9.     <alpha android:fromAlpha="1.0"   
  10.            android:toAlpha="0.0"   
  11.            android:duration="500" />  
  12. </set>  


OK!

posted @ 2014-07-31 13:50  新感觉  阅读(239)  评论(0编辑  收藏  举报