【发布时间】:2011-09-06 08:34:21
【问题描述】:
也许这不是最好的方法,但我的应用程序使用onCreate 将相当多的布局加载/准备到ViewAnimator,所以在应用程序启动后,我的应用程序的每个屏幕都准备好使用。因此更换不同的屏幕既流畅又快速。
这种方法的缺点是,第一个布局需要 5 秒才能出现。确切地说 - ViewAnimator 的所有屏幕都在 XML 布局中定义,我假设它们在 onCreate 期间被膨胀。
我的应用程序必须有一个启动画面,所以我的问题是,是否有办法使用这 5 秒来显示一些图像?
编辑:
感谢您的回答,我想出了这个简单的解决方案:
Activity activity;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_splash);
activity = this;
LinearLayout splash_layout = (LinearLayout) this.findViewById(R.id.splash_layout);
// after 1 second of splash screen, start initializing everything
splash_layout.postDelayed(new Runnable()
{
public void run()
{
activity.setContentView(R.layout.main);
// Here init whole layout and all class
// During initialization, the splashscreen is still visible
}
}, 1000);
}
【问题讨论】:
标签: android multithreading android-layout