我尝试将启动画面添加到我的应用程序,但是当它从启动画面转移到主程序时它停止并且当我尝试将其保留在其他页面中时显示相同
这是我的代码
闪屏.java
public class SplashScreen extends Activity {
ImageView splashimg;
AlphaAnimation animation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
//Set up fade in animation
animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(1000);
splashimg = (ImageView) findViewById(R.id.imageView1);
splashimg.setAnimation(animation);
// Thread to waste time while displaying splash screen
Thread SplashThread = new Thread() {
@Override
public void run() {
try {
synchronized (this) {
// Wait given period of time
wait(3000);
}
} catch (InterruptedException ex) {
}
finish();
// Run next activity
Intent intent = new Intent();
intent.setClass(SplashScreen.this, Main.class);
startActivity(intent);
//Terminate splash screen
SplashScreen.this.finish();
}
};
SplashThread.start();
}
}
主要活动.java
public class MainActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionbar.setTitle("Bahrain Cinema");
ActionBar.Tab Frag1Tab = actionbar.newTab().setText("Home");
ActionBar.Tab Frag2Tab = actionbar.newTab().setText("Showing now");
ActionBar.Tab Frag3Tab = actionbar.newTab().setText("Coming soon");
ActionBar.Tab Frag4Tab = actionbar.newTab().setText("Cinema locator");
Fragment Fragment1 = new Home();
Fragment Fragment2 = new Showing_now();
Fragment Fragment3 = new Coming_soon();
Fragment Fragment4 = new Cinema_locator();
Frag1Tab.setTabListener(new MyTabsListener(Fragment1));
Frag2Tab.setTabListener(new MyTabsListener(Fragment2));
Frag3Tab.setTabListener(new MyTabsListener(Fragment3));
Frag4Tab.setTabListener(new MyTabsListener(Fragment4));
actionbar.addTab(Frag1Tab);
actionbar.addTab(Frag2Tab);
actionbar.addTab(Frag3Tab);
actionbar.addTab(Frag4Tab);
}
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
public MyTabsListener(Fragment fragment){
this.fragment = fragment;
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
ft.replace(R.id.fragment_container, fragment);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
}
谁能帮我?