Android应用的启动画面和加载动画

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();
}
}

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


1
你需要什么类型的动画,进度条还是一些过渡效果?如果你需要进度条,可以参考http://developer.android.com/reference/android/widget/ProgressBar.html,如果你想要一些动画效果,你可以添加平移、缩放和旋转动画。 - Jibran Khan
我想使用这样的动画 [图片] (http://libero.ub.uni-konstanz.de/libero/styles/knub/images/loading_animation.gif)。 - aymen khalifi
进度条控件也类似于您想要的,您只需要使用它 :) - Jibran Khan
1个回答

3

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接