如何在Android Activity屏幕上显示图像的淡入淡出?

Hir*_*ani 39 android image-processing fadein

我想在Android活动屏幕上显示一张照片,从苍白单调的棕褐色到最终的全彩色逐渐淡入淡出.我知道如何在Graphic对象的Java Image/BufferedImage上进行操作,但遗憾的是我对Android编程环境一无所知.有人可以帮忙吗?

Jor*_*sys 77

嗨Hiroshi你可以为淡入淡出做到这一点:

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

在你的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>
Run Code Online (Sandbox Code Playgroud)

但是对于逐渐淡入棕褐色到全彩色,你必须使用TransitionDrawable

  • 工作得很好.你可能不需要`android:repeatCount ="无限"`,但...... (4认同)

Ric*_*cky 53

一旦从完全不透明度点击到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);
Run Code Online (Sandbox Code Playgroud)


小智 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"/>
Run Code Online (Sandbox Code Playgroud)

在java文件中;

 ImageView introanim = (ImageView) findViewById(R.id.introanim);
    Animation StoryAnimation = AnimationUtils.loadAnimation(this, R.anim.intro_anim);
    introanim.startAnimation(StoryAnimation);
Run Code Online (Sandbox Code Playgroud)

你可以从你的棕褐色背景/图片淡出到你想要的任何东西......