Android的 - 加载图像的延迟 [英] Android - Loading images with a delay

查看:134
本文介绍了Android的 - 加载图像的延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想假某种进度条。我包含X的图像和希望有一个的ImageView 具有一定的延迟给他们看。

I'm trying to fake some kind of progress bar. I have X images and want an ImageView to show them with a certain delay.

我一直试图做这样的事情:

I've tried to do something like this:

for(i=2;i<X;i++) 
{
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {  

              @Override
              public void run() {

               drawable = getResources().getDrawable(getResources()
                                .getIdentifier("img_"+i, "drawable", getPackageName()));

               imgPayment.setImageDrawable(drawable);
               }}, DELAY);                  
}

但for循环不等待()的运行结束。我刚才看到的第一个和最后一个图像。我尝试了一些其他的东西,但无法得到想要的结果。

But the for loop doesn't wait for the run() to end. I just see the first and last image. I tried a few other things but couldn't get the desired results.

推荐答案

为什么你不使用动画绘制对象?看来你不是动态加载图像。

Why are you not using an Animation Drawable? It seems that you're not loading the images dynamically.

 <animation-list android:id="@+id/selected" android:oneshot="false">
    <item android:drawable="@drawable/wheel0" android:duration="50" />
    <item android:drawable="@drawable/wheel1" android:duration="50" />
    ...
 </animation-list>

我错过了什么?

链接到文档

链接来样

由于样本文档状态:

要注意的是呼吁的start()方法是很重要的
  AnimationDrawable不能的onCreate()方法时被调用
  您的活动,因为AnimationDrawable尚未完全附
  到窗口。如果你想立即播放动画,无
  要求互动,那么你可能想从叫它
  在你的活动onWindowFocusChanged()方法,将调用
  当Android将你的窗口,成为关注的焦点。

It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus.

这篇关于Android的 - 加载图像的延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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