2

我想在我的应用程序中创建一个 SplashActivity,在屏幕中间显示“正在加载...”,就像 texview 一样。一条消息,而不是图像:)

这是活动:

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

public class SplashActivity extends Activity {

private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 5;    // Sleep for some time

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar
  this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    // Removes notification bar

  setContentView(R.layout.activity_splash);

  // Start timer and launch main activity
  IntentLauncher launcher = new IntentLauncher();
  launcher.start();
 }

 private class IntentLauncher extends Thread {
  @Override
  /**
   * Sleep for some time and than start new activity.
   */
  public void run() {
     try {
        // Sleeping
        Thread.sleep(SLEEP_TIME*1000);

     } catch (Exception e) {
        Log.e(TAG, e.getMessage());
     }

     // Start main activity
     Intent intent = new Intent(SplashActivity.this, MainActivity.class);
     SplashActivity.this.startActivity(intent);
     SplashActivity.this.finish();
  }
 }
}

这是 XML 代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SplashActivity" >

</RelativeLayout>

有谁能够帮我?

4

3 回答 3

1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SplashActivity" >

 <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Next time i should do a basic search. Adding textviews is extrememly basic.
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout> 
于 2013-05-31T15:54:51.510 回答
0

把它放在你的RelativeLayout中:

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="@string/your_message" />
于 2013-05-31T15:54:53.357 回答
0
**Here try this example splashactivity i use in my app....**


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashActivity extends Activity{

private Handler handler;
private Runnable runnable;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    {


    handler = new Handler();
    runnable = new Runnable(){

        @Override
        public void run() {

            try{
                handler.removeCallbacks(runnable);

        }
            finally{
                finish();
                goToActivity();
                handler.removeCallbacks(runnable);
            }
        }
    }; 
    handler.postDelayed(runnable, 1800);
}
}
public void goToActivity(){

    Intent main = new Intent();
    main.setClass(getApplicationContext(), MainActivity.class);
    startActivity(main);

}
@Override
protected void onStart() {
    super.onStart();

}
        }

并且您的布局文件应包含...

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="bottom"
        android:text="Put some text here..."
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#33b5e5"
        android:textSize="25sp"
        android:textStyle="bold"
        android:typeface="normal" />


    </RelativeLayout>
于 2013-05-31T16:05:48.283 回答