0

我遇到以下问题:我的 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 部分。如果有人可以提供帮助,我将不胜感激。

谢谢

4

1 回答 1

0

您必须在 onAnimatinEnd(Animation animation){...} 上编写逻辑,这可能会对您有所帮助...

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) {

            }
        });
于 2013-08-20T07:32:54.183 回答