Android:使View在定义的时间后消失的最佳方法 [英] Android: best way to make a View disappear after a defined amount of time

查看:72
本文介绍了Android:使View在定义的时间后消失的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一段确定的时间之后使textView消失,从而使textView消失.

I would like to make a textView disappear after a define amount of time succeeding a change of the text.

我不确定最好的处理方法是什么.

I am not sure what the best way to proceed is.

使用Thread.sleep(2000);的问题是,它显然会使整个UI线程休眠.在AsyncTask中使用Thread.sleep(2000);似乎是错误的.此外,如果用户离开需要由AsyncTask更新的活动,则会导致问题.

The problem of using Thread.sleep(2000);, is that it would obviously make the whole UI thread sleep. Using Thread.sleep(2000); inside an AsyncTask seems wrong. In addition, it would lead to problems if the user leave the Activity that needs to be updated by the AsyncTask.

必须有一种更清洁的方法来实现这一目标.如果您知道的话:请随时回答:-)

There must be a cleaner way to implement that. If you know any: feel free to answer :-)

推荐答案

您无需创建处理程序:

view.postDelayed(new Runnable(){
  @Override
  public void run()
  {
    view.setVisibility(View.GONE);
  }
}, 10000);

这篇关于Android:使View在定义的时间后消失的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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