如何在Android Activity屏幕上对图像进行淡入淡出?
我想在Android Activity屏幕上显示一张照片,从淡淡的单调棕褐色逐渐淡入到最终的全彩色。我知道如何在Graphic对象的Java Image/BufferedImage上完成它,但不幸的是我对Android编程环境一无所知。谁能帮忙?如何在Android Activity屏幕上对图像进行淡入淡出?
对此的一种方法是使用动画集。看这里;
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);
你可以从你的怀旧背景/淡入到任何你想要的......
喜弘,你可以在褪色做到这一点:
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
工作得很好。你可能不需要'android:repeatCount =“infinite”',虽然... – 2012-06-29 16:42:11
我想要的图像褪色(然后消失)从一次完全不透明点击为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);
感谢这帮助我在回收站内的动画 – AndyRoid 2015-01-01 04:43:39
感谢乔治和麦克。我会尝试你的做法。 – 2010-04-09 12:34:06