【问题标题】:NO Animation Using Method overridePendingTransition();没有动画使用方法 overridePendingTransition();
【发布时间】:2016-07-12 21:03:26
【问题描述】:

在切换 Activity 时看不到动画 第一次活动----------- 第二次活动 没有动画 这是片段

    private void StartAnimations() {
    Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
    anim.reset();
    LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
    l.clearAnimation();
    l.startAnimation(anim);

    anim = AnimationUtils.loadAnimation(this, R.anim.translate);
    anim.reset();
    ImageView iv = (ImageView) findViewById(R.id.splash);
    iv.clearAnimation();
    iv.startAnimation(anim);

    splashTread = new Thread() {
        @Override
        public void run() {
            try {
                int waited = 0;
                // Splash screen pause time
                while (waited < 3500) {
                    sleep(100);
                    waited += 100;
                }
                **Intent intent = new Intent(SplashScreen.this,
                        MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                overridePendingTransition(R.anim.left_in,R.anim.right_in);**

                SplashScreen.this.finish();
            } catch (InterruptedException e) {
                // do nothing
            } finally {
                SplashScreen.this.finish();
            }

        }
    };
    splashTread.start();

}

这是我的动画文件

slide_left_in.xml

     <set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000" android:fromXDelta="-100%" android:toXDelta="0%"/>
<alpha android:duration="5000" android:fromAlpha="0.0" android:toAlpha="1.0" />

slide_right_out.xml

    <set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000" android:fromXDelta="0%" android:toXDelta="100%"/>
<alpha android:duration="5000" android:fromAlpha="1.0" android:toAlpha="0.0" />

所以基本上 OverridePendingTransition 什么都不做

【问题讨论】:

    标签: android android-layout listview android-studio animation


    【解决方案1】:

    你可以使用这个,就像我使用这个一样。不要使用 AnimationUtils,因为在 Activity 中,它只需要 overridePendingTransition...

    public class SplashActivity extends AppCompatActivity {
    
        private static final int SPLASH_TIME = 3000;
        AppPreference preference;
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash);
            preference=new AppPreference(getApplicationContext());
    
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
    
                    if(preference.getLoggedIn()){
                        Intent intent=new Intent(SplashActivity.this,MenuActivity.class);
                        startActivity(intent);
                        overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
                    }
                    else{
                        Intent intent=new Intent(SplashActivity.this,LaunchActivity.class);
                        startActivity(intent);
                        overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
                    }
    
    
                    finish();
                }
            },SPLASH_TIME);
        }
    }
    

    【讨论】:

      【解决方案2】:

      首先将函数中的名称更改为 overridePendingTransition(R.anim.slide_left_in,R.anim.slide_right_in);

      而不是

      overridePendingTransition(R.anim.left_in,R.anim.right_in);

      并删除 intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

      【讨论】:

      • 没有任何改变毕竟还有其他解决方案吗?
      【解决方案3】:
      SplashScreen.this.finish();
      

      overridePendingTransition() 之前并删除

      intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
      

      类似这样的:

      Intent intent = new Intent(SplashScreen.this, MainActivity.class);
      startActivity(intent);
      SplashScreen.this.finish();
      overridePendingTransition(R.anim.left_in,R.anim.right_in);
      

      【讨论】:

      • 没有变化,先生,是一样的
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多