如何使一个闪屏(屏幕应用程序启动时可见)? [英] How to make a splash screen (screen visible when app starts)?

查看:116
本文介绍了如何使一个闪屏(屏幕应用程序启动时可见)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,它开始从净负荷XML的饲料,可以浏览新闻列表,然后阅读详细信息为选定的新闻项目。我希望做的是有一个闪屏,一旦这意味着当你点击应用程序,它应该(在我的情况下,应用程序的名称)显示图像,然后显示已经加载之后才新闻列表。

I have a simple application, it starts, loads xml feed from the net, you can browse a list of news and then read details for a chosen news item. What I would like to do is have a splash screen, meaning as soon as you click application, it should display an image (app name in my case) and then display news list only after they've loaded.

我读到类似的(我认为)的问题,通常人们说用的FrameLayout,但我真的不能把它清除出来。我不知道这是否可以在启动的第一个活动来完成,也许我应该只是显示这个闪屏图像中的一个活动,然后才调用活动展示我的新闻列表?

I read about similar (I think) problems, and usually people say to use FrameLayout, but I can't really sort it out. I'm not sure if this can be done in the first activity that is launched, maybe I should just display this splash image in one activity and only then call activity displaying my news list?

我知道,在iPhone上,你可以在开发的应用程序设置中设置开机画面,将是不错的在Android的应用程序的清单此功能...

I know that on iPhone you can set splash screen in app settings while developing, would be nice to have this functionality in android's app's manifest...

推荐答案

安卓建议你把使用闪屏在启动时进行冗长的计算时的优势。下面是来自Android开发者网站摘录 - 设计为响应:

Android suggests you take advantage of using a splash screen when performing lengthy calculations on start up. Here's an excerpt from the Android Developer Website - Designing for Responsiveness:

如果你的应用程序有一个非常耗时的初始设置阶段,考虑显示启动画面或呈现主视图尽快和填写的信息是异步的。在这两种情况下,你应该表明在某种程度上正在取得进展,以免使用者感知应用程序被冻结。 - Android开发者网站

"If your application has a time-consuming initial setup phase, consider showing a splash screen or rendering the main view as quickly as possible and filling in the information asynchronously. In either case, you should indicate somehow that progress is being made, lest the user perceive that the application is frozen." -- Android Developer Site

您可以创建活动,显示了进度对话框,而使用的AsyncTask从网上下载XML饲料,解析它,将其存储到一个数据库(如果需要),然后开始显示的新闻联播活动。通过调用完成后关闭飞溅活动()

You can create an activity that shows a Progress Dialog while using an AsyncTask to download the xml feed from the net, parse it, store it to a db (if needed) and then start the Activity that displays the News Feeds. Close the splash Activity by calling finish()

下面是一个骨架code:

Here's a skeleton code:


public class SplashScreen extends Activity{
   @Override
   public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      // set the content view for your splash screen you defined in an xml file
      setContentView(R.layout.splashscreen);

      // perform other stuff you need to do

      // execute your xml news feed loader
      new AsyncLoadXMLFeed().execute();

   }

   private class AsyncLoadXMLFeed extends AsyncTask<Void, Void, Void>{
      @Override
      protected void onPreExecute(){
            // show your progress dialog

      }

      @Override
      protected Void doInBackground(Void... voids){
            // load your xml feed asynchronously
      }

      @Override
      protected void onPostExecute(Void params){
            // dismiss your dialog
            // launch your News activity
            Intent intent = new Intent(SplashScreen.this, News.class);
            startActivity(intent);

            // close this activity
            finish();
      }

   }
}

希望帮助!

这篇关于如何使一个闪屏(屏幕应用程序启动时可见)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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