1

This code of mine is not working... I have checked all the links on this site and also tried animation listener but still its not working.

public class SplashScreenPage extends Activity implements Runnable{

Thread splash;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_screen_page_layout);

    splash = new Thread(this);
    splash.start();
}

@SuppressWarnings("static-access")
@Override
public void run() {
    try {
        splash.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    Intent intent = new Intent(SplashScreenPage.this,LoginPage.class);
     startActivity(intent);
     finish();
     SplashScreenPage.this.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
}

@Override
protected void onPause() {
    overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    super.onPause();

}
}
4

3 回答 3

5

问题在于您设备的默认设置。转到设置>显示>动画>允许“所有动画”。这将允许 overridePendingTransition 正常工作。

于 2013-10-30T21:32:13.237 回答
2

我看到的问题是您在主线程的不同线程中使用动画。该主线程也称为 UI 线程。所以,你需要回到那个 UI 线程。这应该有效(我使用 overridePendingTransition(0, 0) 删除任何动画,您可以尝试其他动画:

public class SplashActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_splash);

        presentLogo();
    }

    /** Called to present the Splash image for an amount of time */
    private void presentLogo() {
        final SplashActivity splashActivity = this;
            new Thread() {
                public void run() {
                    synchronized (splashActivity) {
                        try {
                            sleep(Constants.SPLASH_PRESENTATION_DURATION);
                        } catch (InterruptedException e) {
                        } finally {
                            runOnUiThread(new Runnable() {
                                public void run() {
                                    finish();
                                    overridePendingTransition(0, 0);

                                    // After splash, go to the new activity
                                    Intent intent = new Intent();
                                    intent.setClass(splashActivity, LoginActivity.class);
                                    startActivity(intent);
                                }
                         });
                     }
                 }
             }
         }.start();
     }
 }
于 2012-07-31T19:54:10.960 回答
0

尝试这个:

Intent intent = new Intent(SplashScreenPage.this,LoginPage.class);
 startActivity(intent);
 finish();
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
于 2012-07-12T14:06:39.327 回答