Android动画快速结束

时间:2013-08-20 05:49:13

标签: android

我遇到以下问题:我的Android应用程序中有一个动画可以在屏幕上移动UI元素,即它是一个翻译动画,它通常可以正常工作。让我们说它在屏幕中从位置(0,0)移动到(0,200)。问题是,有时这种情况很快发生(如0.001秒),一旦程序加载,我看不到对象的移动,但我看到它处于最终位置(0,200)。这是我的代码:

Handler handler = new Handler();

float height;
private RelativeLayout relativeLayoutDoughnutAndLogoTogether;
private RelativeLayout logo_donut_together2;
private ImageView imgSplash, image2;
private DoughnutView doughnutView;

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    relativeLayoutDoughnutAndLogoTogether = (RelativeLayout) findViewById(R.id.logo_donut_together);
    logo_donut_together2 = (RelativeLayout) findViewById(R.id.logo_donut_together2);
    imgSplash = (ImageView) findViewById(R.id.turkcell_logo);
    image2 = (ImageView) findViewById(R.id.ImageView02);

    int logoHeight = imgSplash.getDrawable().getIntrinsicHeight();
    int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
    final int centerScreen = (screenHeight-logoHeight)/2;

    doughnutView = new DoughnutView(this) {
        @Override
        public void onAnimationComplete() {
                float density = getResources().getDisplayMetrics().density;
                Animation moveToTop = new TranslateAnimation(0, 0, centerScreen-50*density, 0);
                moveToTop.setDuration(1000);                        
                relativeLayoutDoughnutAndLogoTogether.startAnimation(moveToTop);                    

                logo_donut_together2.setVisibility(View.GONE);
                logo_donut_together2.removeView(doughnutView);
                relativeLayoutDoughnutAndLogoTogether.addView(doughnutView);                            
                relativeLayoutDoughnutAndLogoTogether.setVisibility(0);
        }
    };


    doughnutView.setStartAngle(0);
    doughnutView.setColorFront(Color.rgb(232, 232, 232));
    doughnutView.setSweepAngle(360);
    doughnutView.setStrokeWidth(4);
    doughnutView.setMarginAll(10);
    doughnutView.setColorBack(Color.rgb(63, 176, 232));
    doughnutView.startAnimation(0);
    logo_donut_together2.addView(doughnutView);

}

我实际上是在谈论代码的onAnimationComplete部分。如果有人能提供帮助,我将不胜感激。

由于

1 个答案:

答案 0 :(得分:0)

你必须在onAnimationEnd(动画动画)上编写逻辑{...}这可能对你有帮助......

relativeLayoutDoughnutAndLogoTogether.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
            logo_donut_together2.setVisibility(View.GONE);
            logo_donut_together2.removeView(doughnutView);
            relativeLayoutDoughnutAndLogoTogether.addView(doughnutView);                            
            relativeLayoutDoughnutAndLogoTogether.setVisibility(0);

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });