我想在Android Activity屏幕上显示一张照片,并希望它从淡黄色的单色褐变成最终的全彩色,具有渐进和持续的渐变效果。我知道如何在Java Image/BufferedImage上为Graphic对象实现此效果,但不幸的是,我对Android编程环境一无所知。有人能帮忙吗?
我想在Android Activity屏幕上显示一张照片,并希望它从淡黄色的单色褐变成最终的全彩色,具有渐进和持续的渐变效果。我知道如何在Java Image/BufferedImage上为Graphic对象实现此效果,但不幸的是,我对Android编程环境一无所知。有人能帮忙吗?
你好Hiroshi,你可以使用以下代码实现渐变效果:
ImageView myImageView= (ImageView)findViewById(R.id.myImageView);
Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
myImageView.startAnimation(myFadeInAnimation); //Set animation to your ImageView
在您的res\anim\文件夹中有一个名为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
我想让一张图片在被点击后从完全不透明到透明,并最终消失。这是我实现的方式:
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);
其中一种方法是使用动画集。请参见这里;
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"/>
ImageView introanim = (ImageView) findViewById(R.id.introanim);
Animation StoryAnimation = AnimationUtils.loadAnimation(this, R.anim.intro_anim);
introanim.startAnimation(StoryAnimation);
view.animate().alpha(0).setDuration(2000);
/* Alpha attribute translates to opacity.
A solid View means that the alpha attribute is set to 1 (which is the
default) and completely invisible is 0 */
android:repeatCount="infinite"
,虽然... - Bojan Radivojevic