【问题标题】:How add an Application Pre-loader/Startup screen/Splash Screen to My PhoneGap Android App如何将应用程序预加载器/启动屏幕/启动屏幕添加到 My PhoneGap Android 应用程序
【发布时间】:2011-05-03 06:07:38
【问题描述】:

我使用手机 Gap 创建了一个 Android 应用程序。它工作正常。我如何将预加载图像添加到我的应用程序。现在它在加载应用程序时显示一个白页。

非常感谢您的帮助, 谢谢, VKS。

【问题讨论】:

    标签: android cordova


    【解决方案1】:

    如果您的意思是预加载图像有启动画面,请参考以下代码;

    对于PhoneGap:

    public class MyDefaultActivity extends Activity {
    
       public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.setIntegerProperty("splashscreen", R.drawable.splash); // Displays the splash screen for android
            super.loadUrl("file:///android_asset/www/index.html",3000); // Second parameter is duration for delay of splash screen
        }
    }
    

    对于 Android 原生应用:

    public class MySplashScreen extends Activity {
        private CountDownTimer lTimer;
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.splashscreen); // Contains only an LinearLayout with backround as image drawable
    
            lTimer = new CountDownTimer(5000, 1000) {
                public void onFinish() {
                    closeScreen();
                }
                @Override
                public void onTick(long millisUntilFinished) {
                    // TODO Auto-generated method stub
                }
            }.start();
        }
    
        private void closeScreen() {
            Intent lIntent = new Intent();
            lIntent.setClass(this, MyLauncherActivity.class);
            startActivity(lIntent);
            finish();
        }
    }
    

    确保名为splash.png 的文件以res/drawable-hdpi/splash.png (RGBA) 的形式存在。

    【讨论】:

    • 嗨@Vinayak.B 我想问我是否有android webview 应用程序的代码,但是在webview 完全加载之前我想先显示我的公司徽标图像。我在这里写了一个问题: stackoverflow.com/questions/16701179/… 我真的需要你的建议,谢谢 :)
    【解决方案2】:

    您可以创建一个AsyncTask 实现,用于在后台线程中加载应用程序数据时显示图像/进度指示器。

    1. 在异步任务的onPreExecute 显示所选预加载器的方法 (图片/ProgressDialog /等)
    2. doInBackground 方法中你 开始加载必要的数据, 和
    3. onPostExecute 方法中你 删除/隐藏你的预加载器,所以 活动的所需布局将是 显示。

    【讨论】:

      【解决方案3】:

      如果预加载图像是指大图像的低分辨率版本,您可以使用带有两个 ImageView 的 VewSwitcher:一个图像视图包含预加载图像,而另一个包含完整图像(虽然它是加载)。最初,您使预加载的图像可见,但当大位图完成加载后,您只需使用switcher.showNext() 即可显示完整图像。

      一些关于 ViewSwitcher 的进一步阅读(示例做了类似的事情):here

      【讨论】:

        猜你喜欢
        • 2013-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多