startAnimation没有点击按钮

时间:2013-06-03 09:04:36

标签: android android-layout animation layout android-animation

我正在尝试从布局到布局的动画。我尝试了这个代码,并保存在一个方法中,我没有被执行,即它没有带我到另一个布局

这是我的代码

private void showNextScreen() {
    Animation animation = AnimationUtils.loadAnimation(context,
            R.anim.push_left_in);
    animation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {

            startActivity(new Intent(context, MainLoginSignUpActivity.class));
            finish();
            overridePendingTransition(R.anim.push_left_in,
                    R.anim.push_left_out);
        }
    });// What to add here "startAnimation(animation);" --> But this shows error how to add it
}

在此之前我从这段代码中调用此方法

context = this;
        new CountDownTimer(3000, 1000) {
            @Override
            public void onFinish() {
                showNextScreen();
            }

            @Override
            public void onTick(long millisUntilFinished) {
            }
        }.start();

请帮助解决此问题。提前致谢

1 个答案:

答案 0 :(得分:1)

我以这种方式展示动画。检查代码

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcomescreen);


    new Handler().postDelayed(new Runnable() {

    public void run() {

        Intent mainIntent = new Intent(MainActivity.this,LoginScreen.class);
        MainActivity.this.startActivity(mainIntent);
        MainActivity.this.finish();
        overridePendingTransition(R.anim.mainfadein, R.anim.splashfadeout);
        }
    }, CommonVariables.SPLASH_DISPLAY_TIME);

}   }

这里是动画xml:mainfadein.xml

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="1000"/>

和splashfadeout.xml

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:zAdjustment="top"
    android:fromAlpha="1.0"
    android:toAlpha="0.0"
    android:duration="1000"/>