即使我收到通知已经结束,我也看不到安卓动画

时间:2014-08-27 22:15:11

标签: android xml animation views

我一直在尝试在我的Android视图上使用动画 - 首先使用普通动画,然后使用LayoutAnimationController。 onAnimationEnd()中的代码会执行,但我不会在屏幕上看到任何内容。

这是XML文件

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
    <translate>
        android:toXDelta="50%"` android:duration="3000" android:fillAfter="true"
    </translate>
</set>

这是Java代码:

loginLayOut = (RelativeLayout) findViewById(R.id.login_view);

Animation RightToLeft = AnimationUtils.loadAnimation(this, R.anim.login_screen_animation);
LayoutAnimationController layoutAnimationController = new LayoutAnimationController(RightToLeft);
loginLayOut.setLayoutAnimation(layoutAnimationController);

if (RightToLeft != null) {
    RightToLeft.setAnimationListener(new Animation.AnimationListener() {@
        Override
        public void onAnimationStart(Animation animation) {

        }

        @
        TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)@ Override
        public void onAnimationEnd(Animation animation) {
            loginLayOut.clearAnimation();


            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                loginLayOut.getWidth(), loginLayOut.getHeight());
            lp.setMargins(0, 0, 0, 0);
            //lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            lp.removeRule(RelativeLayout.RIGHT_OF);
            lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
            loginLayOut.setLayoutParams(lp);
            Log.d("Animate", "View has animated");

        }

        @
        Override
        public void onAnimationRepeat(Animation animation) {

        }
    });


    loginLayOut.startAnimation(RightToLeft);
}

0 个答案:

没有答案