gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:47:04 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com