如何在android中从左到右的动画效果开始飞溅活动(第一次活动)(How to start splash activity(very first activity) from left to rig

编程入门 行业动态 更新时间:2024-10-28 00:23:53
如何在android中从左到右的动画效果开始飞溅活动(第一次活动)(How to start splash activity(very first activity) from left to right animation effect in android)

我在android中做了一个活动,我想要的是当我启动应用程序时,我的应用程序中的第一个活动应该从左侧滑动到右侧动画效果。但我不知道如何实现它,所以任何人都可以帮助我或给我一些技巧,以便我可以解决它。我有我的项目动画XML准备。

预先感谢我的代码:

package com.esp.Estorec.ui; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.Window; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.RelativeLayout; public class SplashActivity1 extends Activity implements AnimationListener { RelativeLayout view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); view=(RelativeLayout)findViewById(R.id.splash1); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_splash1); Animation animationSlideInLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); animationSlideInLeft.setAnimationListener(new AnimationListener(){ @Override public void onAnimationEnd(Animation animation) { // if you need to do something } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { }}); view.startAnimation(animationSlideInLeft); new Handler().postDelayed(new Runnable() { @Override public void run() { handler.sendEmptyMessage(1); } }, 2000); } private Handler handler = new Handler() { @SuppressWarnings("deprecation") @Override public void handleMessage(android.os.Message msg) { try { Intent intent = null; intent = new Intent(SplashActivity1.this, SplashActivity2.class); startActivity(intent); overridePendingTransition(R.anim.animated_activity_slide_left_in, R.anim.animated_activity_slide_right_out); finish(); } catch (Exception e) { } } }; @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } }

I have made an activity in android,I want is when i start the app the very first activity in my app should come from left and slide to right animation effect.but i have no idea about how to implement it,So can anyone help me or give me some trick so that i can solve it out.I have animation XML ready with my project.

Thank you in advance my code:

package com.esp.Estorec.ui; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.Window; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.RelativeLayout; public class SplashActivity1 extends Activity implements AnimationListener { RelativeLayout view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); view=(RelativeLayout)findViewById(R.id.splash1); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_splash1); Animation animationSlideInLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); animationSlideInLeft.setAnimationListener(new AnimationListener(){ @Override public void onAnimationEnd(Animation animation) { // if you need to do something } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { }}); view.startAnimation(animationSlideInLeft); new Handler().postDelayed(new Runnable() { @Override public void run() { handler.sendEmptyMessage(1); } }, 2000); } private Handler handler = new Handler() { @SuppressWarnings("deprecation") @Override public void handleMessage(android.os.Message msg) { try { Intent intent = null; intent = new Intent(SplashActivity1.this, SplashActivity2.class); startActivity(intent); overridePendingTransition(R.anim.animated_activity_slide_left_in, R.anim.animated_activity_slide_right_out); finish(); } catch (Exception e) { } } }; @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } }

最满意答案

将“视图”替换为最外面的布局名称。 将此代码写入您想要动画发生的活动的oncreate方法中。

animationSlideInLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); animationSlideInLeft.setDuration(1500); animationSlideInLeft.setAnimationListener(new AnimationListener(){ @Override public void onAnimationEnd(Animation animation) { // if you need to do something } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { }}); view.startAnimation(animationSlideInLeft);

Replace "view" with your outermost Layout name. Write this code in your oncreate method of the activity that you want the animation to occur.

animationSlideInLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); animationSlideInLeft.setDuration(1500); animationSlideInLeft.setAnimationListener(new AnimationListener(){ @Override public void onAnimationEnd(Animation animation) { // if you need to do something } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { }}); view.startAnimation(animationSlideInLeft);

更多推荐

本文发布于:2023-04-27 22:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329033.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:效果   动画   如何在   左到右   start

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!