使用淡入淡出TransitionDrawable不工作的机器人 [英] Crossfading using TransitionDrawable not working on android

查看:241
本文介绍了使用淡入淡出TransitionDrawable不工作的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个图像,我想淡入淡出。 最初,它们都使用ImageView的。然后,我用.getDrawable()来获取图像的绘制。

I have two Images that I want to cross fade. Initially they both use imageview. I then use .getDrawable() to get the drawable of the images.

这是在code我用

Drawable backgrounds[] = new Drawable[2];
           backgrounds[0] = BackgroundImage.getDrawable();
           backgrounds[1] = BackgroundImageBlurred.getDrawable();

           TransitionDrawable crossfader = new TransitionDrawable(backgrounds);
           crossfader.startTransition(3000);

有只示出了第一个数组元素,它无论如何表示由于两个图像被设置为可见在XML上的图像。

It only shows the image on the first array element, which it shows anyway since both images were set to visible in the XML.

过渡不启动

任何帮助将是AP preciated :)

Any help would be appreciated :)

推荐答案

下面是一个例子的如果的你有2个可绘制,并希望动画的一些 ImageView的过渡

Here's an example IF you have 2 drawables and want to animate their transition in some ImageView:

package com.example.app;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.widget.ImageView;

 class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Drawable backgrounds[] = new Drawable[2];
        Resources res = getResources();
        backgrounds[0] = res.getDrawable(android.R.drawable.btn_star_big_on);
        backgrounds[1] = res.getDrawable(android.R.drawable.btn_star_big_off);

        TransitionDrawable crossfader = new TransitionDrawable(backgrounds);

        ImageView image = (ImageView)findViewById(R.id.image);
        image.setImageDrawable(crossfader);

        crossfader.startTransition(3000);

    }
}

然后,如果你想转换回原始图像,你可以叫

Then if you want to transition back to the original image you can call

// Make sure the transition occurred
crossfader.startTransition(0);
// Reverse transition
crossfader.reverseTransition(3000);

请纠正我,如果我误解了你的问题。

Please correct me if I misunderstood your question.

这篇关于使用淡入淡出TransitionDrawable不工作的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆