1

我在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

    }


}
4

3 回答 3

3

在你的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>
于 2013-08-13T11:27:23.770 回答
2

将“view”替换为最外层的布局名称。在您希望动画发生的活动的 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);
于 2013-08-13T11:14:08.527 回答
1

将您的活动的背景颜色设置为白色(#FFF),创建一个图像视图并且该图像视图应该是透明的,然后使用您想要的绘图数量编写一个 XML 动画。最后在imageview中启动动画。这应该可以解决问题。

于 2013-08-13T11:15:59.597 回答