1

我正在使用Phonegap + Jquery mobile开发一个android应用程序,我在启动应用程序时显示了一个启动画面,但它是一个静态png文件,现在我的客户不断要求在启动画面中提供一些加载指示器,如微调器或进度条当用户等待应用程序加载时。

我按照一个示例在启动屏幕中显示进度条,但它不起作用,下面是我的代码。

主Java:

super.onCreate(savedInstanceState);

final Activity activity = this;
final ProgressBar progessBar1;
View footer = View.inflate(getContext(), R.layout.spinner, null);
root.addView(footer);

progessBar1 = (ProgressBar) findViewById(R.id.progressBar1);

this.appView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int progress) { 
            activity.setProgress(progress * 1000);
            if(progress < 100 && progessBar1.getVisibility() == ProgressBar.GONE) {
                progessBar1.setVisibility(ProgressBar.VISIBLE);
            }
            progessBar1.setProgress(progress);
            if(progress == 100) {
                progessBar1.setVisibility(ProgressBar.GONE);
            }

            Log.d("Progress", progress+"");

         }
    });

super.setIntegerProperty("splashscreen", R.drawable.splash);
super.setStringProperty("loadingDialog", "Wait, loading packages ...");


super.loadUrl("file:///android_asset/www/index.html", 12000);
super.setIntegerProperty("loadUrlTimeoutValue", 12000); 

和 res/layout 中的 spinner.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:maxHeight="10dip"
        android:minHeight="10dip" />

</LinearLayout>

但它不显示进度条。

我的问题:

  1. 任何人都可以帮助指出我做错了什么,谢谢。

  2. 任何其他方式来做到这一点,实际上我只想在启动屏幕上显示一个微调器,就可以了。

4

3 回答 3

1

确保您的初始图像具有透明背景。

Splashscreen 占据了整个屏幕空间,隐藏了进度条。我试图将在初始屏幕上也没有显示的进度条带到front()。

我尝试运行您的代码,它会引发空指针异常

    this.appView.setWebChromeClient.....

因为appView在这一行是空的。

我将代码更改为以下内容((即在 setwebchromeclient 之前加载 url),它同时显示了启动画面和进度条。

    super.onCreate(savedInstanceState);

    final Activity activity = this;
    final ProgressBar progessBar1;

    super.setIntegerProperty("splashscreen", R.drawable.splash);
    super.setStringProperty("loadingDialog", "Wait, loading packages ...");
    super.loadUrl("file:///android_asset/www/index.html", 20000);
    super.setIntegerProperty("loadUrlTimeoutValue", 20000);


    View footer = View.inflate(getContext(), R.layout.testspinner, null);
    root.addView(footer);

    progessBar1 = (ProgressBar) findViewById(R.id.progressBar11);

    this.appView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int progress) {
            activity.setProgress(progress * 1000);
            if (progress < 100
                    && progessBar1.getVisibility() == ProgressBar.GONE) {
                progessBar1.setVisibility(ProgressBar.VISIBLE);
            }
            progessBar1.setProgress(progress);
            if (progress == 100) {
                progessBar1.setVisibility(ProgressBar.GONE);
            }

            Log.d("Progress", progress + "");

        }
    });

在此处输入图像描述

于 2013-06-11T07:10:31.530 回答
0

我相信这也不会是你想要的样子。在某一点添加了相同的 ProgressBar 小部件,并且它是相同的(丑陋的)加载栏 - 至少在我的 droid3 上 - 当您通过浏览器查看网页时,它会显示在操作系统浏览器上。这不利于“原生”的外观和感觉。

于 2013-06-13T20:12:23.357 回答
0

是的,您收到 nullpointer 异常,因为代码中进度条的 id 与布局文件中的 id 不匹配。

以下行

com.accoladewios.apps.jetabout.MainActivity$1.onProgressChanged(MainActivity.java:42)

表示空指针异常的第 42 行。

splash.xml中的进度条 ID是progressBar1。而代码中的以下行使用progressbar1

progessBar1 = (ProgressBar) findViewById(R.id.progressbar1 );

如果您调试代码,则运行上述行后的变量progessBar1将为空。

修复此问题,启动画面应显示进度条。

于 2013-06-18T19:24:28.440 回答