android - 带有加载动画的启动画面(Android 应用程序)

标签 android multithreading

我正在使用 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();
}
}

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

最佳答案

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

<ProgressBar
    android:id="@+id/my_progress_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    .....
/>

关于android - 带有加载动画的启动画面(Android 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17064542/

相关文章:

java - 如何在Activity中正确设置CountDownTimer

java - Java中定时任务的并发执行

java - java中有没有默认的线程池

multithreading - 使用Amazon EC2多核或多个计算单元时,您是否需要分拆CPU工作?

ruby - Ruby 中的线程作用域

c - OpenMP - 在包含并行 for 循环的并行区域中串行化 for 循环

android - 从服务使用 : runOnUiThread or AsyncTask or Handler or Post

java - 将 ImageView 的大小调整为另一个 ImageView 的大小的动画

java - 防止哈希表转换为 ASCII

android - 如何检测启动应用程序的完成?