android视图之间的时间延迟
Posted
技术标签:
【中文标题】android视图之间的时间延迟【英文标题】:android time delay between views 【发布时间】:2011-06-24 10:14:05 【问题描述】:我不确定,是什么阻止了它的工作。我有代码设置导致 3 秒的时间延迟,但视图不工作,它保持黑色,然后在 3 秒后切换到下一个屏幕。我想,我正在做延时,并且在 android 中没有调用某些东西来显示布局......
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
start = System.currentTimeMillis();
setContentView(R.layout.team);
protected void onStart()
super.onStart();
while(game)
now = System.currentTimeMillis();
if (now - start >= 5000)
game = false;
Intent about = new Intent(this, SplashScreen.class);
startActivity(about);
【问题讨论】:
【参考方案1】:我相信您想实现一个延迟几秒钟的屏幕,然后启动您的主应用程序。就像主应用程序启动之前的启动画面一样吗?
那么这对你有帮助!
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** set time to splash out */
final int welcomeScreenDisplay = 4000;
/** create a thread to show splash up to splash time */
Thread welcomeThread = new Thread()
int wait = 0;
@Override
public void run()
try
super.run();
/**
* use while to get the splash time. Use sleep() to increase
* the wait variable for every 100L.
*/
while (wait < welcomeScreenDisplay)
sleep(100);
wait += 100;
catch (Exception e)
System.out.println("EXc=" + e);
finally
/**
* Called after splash times up. Do some action after splash
* times up. Here we moved to another main activity class
*/
startActivity(new Intent(CurrentActivity.this, NextActivity.class));
finish();
;
welcomeThread.start();
这是一个延迟 4 秒的屏幕。
【讨论】:
【参考方案2】:您应该使用 Timer 类来启动新活动。
【讨论】:
以上是关于android视图之间的时间延迟的主要内容,如果未能解决你的问题,请参考以下文章
在android(初级)的Listview上延迟加载图像? [复制]