我对android开发非常陌生,正在尝试一点一点地掌握它!
我正在尝试实现启动画面,并希望它在切换到下一个活动之前执行动画。我一直试图弄清楚一两个小时,但偶然发现了这个网站,所以这里......这就是我试过的,
public class SplashActivity extends Activity {
// THREAD TO PROCESS SPLASH SCREEN
private Thread splashThread;
// ANIMATION END FIELD
private boolean ANIMATION_END;
// CALLED WHEN ACTIVITY IS FIRST CREATED
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// SET THE SPLASH SCREEN XML LAYOUT
setContentView(R.layout.splash);
// GET THE SPLASH IMAGE
final ImageView logo = (ImageView) findViewById(R.id.splash_logo);
// LOAD START ANIMATION FOR SPLASH IMAGE
final Animation slideIn = AnimationUtils.loadAnimation(this, R.anim.slide_in_right);
// START ANIMATE SPLASH LOGO
logo.startAnimation(slideIn);
// END ANIMATION SPLASH LOGO
final Animation slideOut = AnimationUtils.loadAnimation(this, R.anim.slide_out_left);
// SET EVENT LISTENER FOR ANIMATION TO FINISH
slideOut.setAnimationListener(new Animation.AnimationListener(){
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
ANIMATION_END = true;
}
});
// SET SPLASHSCREEN THREAD
splashThread = new Thread() {
@Override
public void run() {
try {
synchronized(this) {
// DURATION OF SPLASH SCREEN
wait(4000);
}
} catch (InterruptedException e) {
}
logo.startAnimation(slideOut);
// IF ANIMATION HAS ENDED
if (ANIMATION_END == true) {
finish();
// SWITCH FROM SPLASH ACTIVITY TO MENU ACTIVITY
startActivity(new Intent(SplashActivity.this, MenuActivity.class));
}
}
};
// RUN THE SPLASH THREAD
splashThread.start();
}
// SPLASH SCREEN TOUCH EVENTS
@Override
public boolean onTouchEvent(MotionEvent event) {
// USER TOUCHES SPLASH SCREEN
if (event.getAction() == MotionEvent.ACTION_DOWN) {
synchronized(splashThread) {
// MAKE SPLASH SCREEN END
splashThread.notifyAll();
}
}
return true;
}
}
可能不是我知道的最好的代码,但我正在尝试。在徽标滑入后,当它尝试切换到MenuActivity
感谢所有帮助的人!