如何启动飞溅活动(第一个活动)由左到Android中右的动画效果(How to start spla

2019-10-18 12:08发布

我已在Android的一个活动,我想是当我启动应用程序在我的应用程序的第一个活动应该来自左,滑向右动画effect.but我不知道如何实现它的想法,因此,任何人可以帮助我或者给我一些诀窍,这样我就可以解决这个问题out.I有动画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

    }


}

Answer 1:

替换“视图”与您最外层的布局名称。 在你要出现在动画活动的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);


Answer 2:

定义你的styles.xml一个新的动画风格,如下

    <style name="MyTheme.Window" parent="@android:style/Animation.Activity">
      <item name="android:activityOpenEnterAnimation">@anim/your_desired_animation</item>
      <item name="android:activityOpenExitAnimation">@anim/your_desired_animation</item>
      <item name="android:activityCloseEnterAnimation">@anim/your_desired_animation</item>
      <item name="android:activityCloseExitAnimation">@anim/your_desired_animation</item>
    </style>

然后设置这种风格的主题(的themes.xml)如下:

<style name="MyTheme" parent="@android:style/Theme">
      <item name="android:windowAnimationStyle">@style/MyTheme.Window</item>
</style>

然后你就可以在你的AndroidManifest.xml中简单地设置这些主题的每一次活动如下:

<activity 
  android:name="your_activity" 
  android:theme="@style/MyTheme">
</activity>


Answer 3:

将您的活动的背景色为白色(#FFF),创建的ImageView和ImageView的应该是透明的,然后使用写你想要绘制资源量的XML动画。 终于开始在ImageView的动画。 这应该做的伎俩。



文章来源: How to start splash activity(very first activity) from left to right animation effect in android