如何在 Android 活动屏幕上淡入图像?

发布于 2024-08-27 17:27:34 字数 137 浏览 6 评论 0原文

我想在 Android 活动屏幕上显示一张照片,并从浅单调的棕褐色逐渐持续淡入到最终的全色。我知道如何在 Java Image/BufferedImage 上为 Graphic 对象执行此操作,但不幸的是我对 Android 编程环境一无所知。有人可以帮忙吗?

I'd like to display a photo on an Android Activity screen with doing gradual and continual fade-in from pale monotone sepia to the final full color. I know how to do it on a Java Image/BufferedImage for the Graphic object but unfortunately I know nothing for the Android programming environment. Could anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

赴月观长安 2024-09-03 17:27:34

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

Hi Hiroshi you can do this for the fade in:

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

and inside your res\anim\ folder the animation file 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>

but for the gradual fade in from sepia to the full color, you must use TransitionDrawable

与他有关 2024-09-03 17:27:34

我希望图像在从完全不透明度单击到 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);

I wanted an image to fade (and then disappear) once clicked from full opacity to 0. Here is how I did it:

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);
淡忘如思 2024-09-03 17:27:34

一种方法是使用动画集。参见这里;

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);

你可以从你的棕褐色背景/图片淡入任何你想要的......

One method for this would be to use the animation set. See here;

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

Some example code I have done (infinite loop fade out in this example) ;

In the animation .xml file;

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

In the java file;

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

You could fade from your sepia background/picture to whatever you want...

呢古 2024-09-03 17:27:34

另一个更简单的解决方案是只需将一个存根 onClick 方法放入您想要淡入淡出的 ImageView 中,然后在该方法中添加以下内容:

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 */

Another much simpler solution is to just put a stub onClick method to your ImageView you want to fade, then inside the method you add this:

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 */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文