简体   繁体   English

更改ImageView几秒钟并暂停UI

[英]Change ImageView for a few seconds and pause UI

Sorry, I keep on trying to adapt the tokens, but somehow I can't manage this one. 抱歉,我一直在尝试调整令牌,但是以某种方式我无法管理它。

I have the following code: 我有以下代码:

  timer.schedule(new TimerTask(){

     runOnUiThread(new Runnable() {

      public void run(){
      SplashImage.setImageDrawable(aktieknop);}

      });

  },SplashTime);
  }

Like this the code 'works': 像这样的代码“工作”:

  timer.schedule(new TimerTask(){

    // runOnUiThread(new Runnable() {

      public void run(){
      SplashImage.setImageDrawable(aktieknop);}

    //  });

  },SplashTime);
  }

Can you please help me solving this silly issue? 您能帮我解决这个愚蠢的问题吗? Thanks a lot! 非常感谢!

You must call this code line " SplashImage.setImageDrawable(nSplashImage); " from your run method in a runOnUIThread() method like this: 您必须在runOnUIThread()方法的run方法中从以下代码行调用此代码行“ SplashImage.setImageDrawable(nSplashImage); ”:

runOnUiThread(new Runnable() {
public void run() {
    SplashImage.setImageDrawable(nSplashImage);
}

}); });

This is because you cannot change UI components on a non UI thread. 这是因为您不能在非UI线程上更改UI组件。

For the splash Screen you can use the Handler and send the delayed message. 对于启动画面,您可以使用处理程序并发送延迟的消息。

Handler splashHandler = new Handler() {

    @Override
    public void handleMessage(Message msg) {
             super.handleMessage(msg);
              //Here you can do what ever you want

           }
         };

int SPLASHTIME=2000;//your wish int SPLASHTIME = 2000; //您的愿望

splashHandler.sendMessageDelayed(msg, SPLASHTIME);

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

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