3

我正在使用 eclipse adt 开发我的第一个 android 应用程序。我成功制作了启动画面,但我想显示加载动画。我有以下代码:

package com.sunil.splash;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

public class Splash extends Activity {
private long ms=0;
private long splashTime=2000;
private boolean splashActive = true;
private boolean paused=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Hides the titlebar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.splash);

    Thread mythread = new Thread() {
        public void run() {
            try {
                while (splashActive && ms < splashTime) {
                    if(!paused)
                        ms=ms+100;
                    sleep(100);
                }
            } catch(Exception e) {}
            finally {
                Intent intent = new Intent(Splash.this, Home.class);
                startActivity(intent);
            }
        }
    };
    mythread.start();
}
}

你能帮我解决这个问题吗?

4

1 回答 1

3

Android 有一个默认的不确定进度小部件。只需将其添加到您的加载程序布局 (splash.xml):

<ProgressBar
    android:id="@+id/my_progress_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    .....
/>
于 2013-06-12T12:39:48.123 回答