[英]How can i add animation to the splash screen?
I don't know why but animations for splash screen isn't working at all.我不知道为什么,但是启动画面的动画根本不起作用。 I guess my codes are correct!.. All I want is to perform the animation on the splash screen content.
我想我的代码是正确的!.. 我想要的只是在闪屏内容上执行动画。
public class Welcome extends AppCompatActivity {
Animation topAnim, bottomAnim;
ImageView imageView;
TextView textView;
private static int SPLASH_TIME_OUT=4000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setContentView(R.layout.activity_welcome);
topAnim = AnimationUtils.loadAnimation(this,R.anim.top_animation);
bottomAnim = AnimationUtils.loadAnimation(this,R.anim.bottom_animation);
imageView = findViewById(R.id.imageView3);
textView = findViewById(R.id.textView);
imageView.startAnimation(topAnim);
textView.startAnimation(bottomAnim);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_welcome);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent homeIntent =new Intent(Welcome.this,MainActivity.class);
startActivity(homeIntent);
finish();
}
},SPLASH_TIME_OUT);
}
}
These are the bottom and top animations .xml files respectively这些分别是底部和顶部动画 .xml 文件
<translate
android:fromXDelta="0%"
android:fromYDelta="100%"
android:duration="1500" />
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="1500" />
<translate
android:fromXDelta="0%"
android:fromYDelta="-50%"
android:duration="2000" />
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="1500" />
Replace this line替换这一行
getWindow().setContentView(R.layout.activity_welcome);
With和
setContentView(R.layout.activity_welcome);
And remove setContentView(R.layout.activity_welcome);
并删除
setContentView(R.layout.activity_welcome);
from above从上面
new Handler().postDelayed(new Runnable() {
Just remove the followimg line:只需删除以下行:
setContentView(R.layout.activity_welcome); setContentView(R.layout.activity_welcome);
above this line: new Handler().postDelayed(new Runnable() {在这一行之上: new Handler().postDelayed(new Runnable() {
And it would work fine.它会工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.