简体   繁体   English

Android淡出至新视图

[英]Android Fade Out To New View

I have an ImageView. 我有一个ImageView。 When I change its image resource, I want to fade to the new resource. 更改其图像资源时,我想淡入新资源。 (I don't want the old resource to fade out and the new one to fade in; I want the new one to already be in the background and the old image to fade out, revealing the new image.) Is there a way to do this with only one View? (我不希望旧资源消失,而新资源消失;我希望新资源已经存在于背景中,而旧图像则消失,从而揭示新图像。)是否有办法仅使用一个视图即可做到这一点? I don't want to use two stacked Views because I need to do this with enough images that it would be bad for performance. 我不想使用两个堆叠的视图,因为我需要使用足够多的图像来执行此操作,这会降低性能。 Right now, I just have the basics: 现在,我只具备基本知识:

fadeout animation 淡出动画

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

using fadeout animation on the View 在视图上使用淡出动画

Animation fadeout = AnimationUtils.loadAnimation(this, R.anim.fadeout);
fadeout.setDuration(0);
boardView[location].startAnimation(fadeout);

Now, I need to somehow make the new image appear in the background as the View is fading out. 现在,我需要以某种方式使新图像在视图逐渐消失时显示在背景中。 Is this possible without adding a second View in the background? 是否可以在后台不添加第二个View的情况下实现?

ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(view, View.ALPHA, 1,0);

This would be the one of the way to do fade in/out animation. 这将是淡入/淡出动画的方法之一。 You just needs to the pass the view to which perform the animation, objectAnimator supports from honeycomb version 您只需要传递执行动画的视图,objectAnimator支持蜂窝版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM