第一种方法:
public class SplashScreen extends Activity
{
private Thread mSplashThread;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
splashImageView.setBackgroundResource(R.drawable.flag);
final AnimationDrawable frameAnimation = (AnimationDrawable) splashImageView
.getBackground();
splashImageView.post(new Runnable()
{
public void run()
{
frameAnimation.start();
}
});
mSplashThread = new Thread()
{
public void run()
{
try
{
synchronized (this)
{
wait(2000);
}
}
catch (InterruptedException ex)
{
}
finish();
}
};
mSplashThread.start();
}
}
main.xml文件:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TheSplashLayout"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/SplashImageView"
android:layout_gravity="center">
</ImageView>
</LinearLayout>
第二种方法
1.anim/loading内容
<animation-list android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="200" android:drawable="@drawable/logo1" />
<item android:duration="200" android:drawable="@drawable/logo3" />
<item android:duration="200" android:drawable="@drawable/logo5" />
</animation-list>
2.values下建立styles.xml
<style name="ListProgressStyle" >
<item name="android:indeterminateDrawable">@anim/loading</item>
</style>
3.main.xml
<ProgressBar android:id="@+id/ProgressBar01"
style="@style/ListProgressStyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ProgressBar>
在activity中显示即可
public class SplashScreen extends Activity
{
private Thread mSplashThread;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
splashImageView.setBackgroundResource(R.drawable.flag);
final AnimationDrawable frameAnimation = (AnimationDrawable) splashImageView
.getBackground();
splashImageView.post(new Runnable()
{
public void run()
{
frameAnimation.start();
}
});
mSplashThread = new Thread()
{
public void run()
{
try
{
synchronized (this)
{
wait(2000);
}
}
catch (InterruptedException ex)
{
}
finish();
}
};
mSplashThread.start();
}
}
main.xml文件:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TheSplashLayout"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/SplashImageView"
android:layout_gravity="center">
</ImageView>
</LinearLayout>
第二种方法
1.anim/loading内容
<animation-list android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="200" android:drawable="@drawable/logo1" />
<item android:duration="200" android:drawable="@drawable/logo3" />
<item android:duration="200" android:drawable="@drawable/logo5" />
</animation-list>
2.values下建立styles.xml
<style name="ListProgressStyle" >
<item name="android:indeterminateDrawable">@anim/loading</item>
</style>
3.main.xml
<ProgressBar android:id="@+id/ProgressBar01"
style="@style/ListProgressStyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ProgressBar>
在activity中显示即可