gpt4 book ai didi

android - 没有动画使用方法 overridePendingTransition();

转载 作者:行者123 更新时间:2023-11-30 01:11:53 35 4
gpt4 key购买 nike

切换 Activity 时看不到动画第一个 Activity ---------------- 第二个 Activity 无动画这是 fragment

    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 什么都不做

最佳答案

你可以使用这个,因为我用过这个。不要使用 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);
}
}

关于android - 没有动画使用方法 overridePendingTransition();,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38338836/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com