2010-04-08 52 views

回答

6

對此的一種方法是使用動畫集。看這裏;

http://developer.android.com/guide/topics/resources/available-resources.html#animation

一些示例代碼我已經做(無限循環淡出在這個例子中);

在動畫的.xml文件中;

<alpha android:fromAlpha="1.0" 
     android:toAlpha="0.3" 
     android:duration="7000" 
     android:repeatMode="restart" 
     android:repeatCount="infinite"/> 

在java文件中;

ImageView introanim = (ImageView) findViewById(R.id.introanim); 
    Animation StoryAnimation = AnimationUtils.loadAnimation(this, R.anim.intro_anim); 
    introanim.startAnimation(StoryAnimation); 

你可以從你的懷舊背景/淡入到任何你想要的......

+0

感謝喬治和麥克。我會嘗試你的做法。 – 2010-04-09 12:34:06

76

喜弘,你可以在褪色做到這一點:

ImageView myImageView= (ImageView)findViewById(R.id.myImageView); 
    Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein); 
    myImageView.startAnimation(myFadeInAnimation); //Set animation to your ImageView 

和你的資源內\動畫\文件夾中的動畫文件fadein.xml

<?xml version="1.0" encoding="UTF-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
     <alpha 
      android:fromAlpha="0.0" 
      android:toAlpha="1.0" 
      android:interpolator="@android:anim/accelerate_interpolator" 
      android:duration="3000"/> 
</set> 

但對於從褐色到全綵色的逐漸淡去,喲ü必須使用TransitionDrawable

+4

工作得很好。你可能不需要'android:repeatCount =「infinite」',雖然... – 2012-06-29 16:42:11

50

我想要的圖像褪色(然後消失)從一次完全不透明點擊爲0。這裏是我是如何做到的:

Animation a = new AlphaAnimation(1.00f, 0.00f); 

a.setDuration(1000); 
a.setAnimationListener(new AnimationListener() { 

    public void onAnimationStart(Animation animation) { 
     // TODO Auto-generated method stub 

    } 

    public void onAnimationRepeat(Animation animation) { 
     // TODO Auto-generated method stub 

    } 

    public void onAnimationEnd(Animation animation) { 
     yourView.setVisibility(View.GONE); 

    } 
}); 

yourView.startAnimation(a); 
+0

感謝這幫助我在回收站內的動畫 – AndyRoid 2015-01-01 04:43:39