我想逐个展示两个闪屏。每次用户登录时,首先要离开静态秒。我每次都会改变第二个闪屏,但我不知道如何设置第一个静态闪屏。
这是我的.java文件
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.widget.ImageView;
import android.app.Activity;
import android.content.Intent;
public class SplashScreen extends DefaultActivity {
int timeout = 2000; // Choose the delay (1000 = 1 second)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
setFonts();
// Randomise a background
int[] yourListOfImages= {R.drawable.test, R.drawable.test1, R.drawable.test2, R.drawable.test3};
Random random = new Random(System.currentTimeMillis());
int posOfImage = random.nextInt(yourListOfImages.length);
ImageView imageView= (ImageView) findViewById(R.id.imageView1);
imageView.setBackgroundResource(yourListOfImages[posOfImage]);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//Redirecting to the home page
Intent redirect = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(redirect);
finish();
}
}, timeout);
}
}
这是.xml失败
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".SplashScreen" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="@string/contentDescription"
android:background="@android:color/white" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="@string/contentDescription"
android:background="@android:color/white" />
<TextView
android:id="@+id/textViewSplash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="45dp"
android:textColor="#FFFFFF"
android:textSize="25sp"
android:tag="helvetica"
android:text="@string/splash_intro" />
</RelativeLayout>