簡體   English   中英

在開始新活動之前允許動畫完成

[英]Allow an animation to finish before starting a new activity

我想在切換到新活動之前在圖像上執行動畫。 我還想確保在新活動開始之前動畫已完全完成。 下面是我用來完成任務的代碼。

public boolean onTouch(View view, MotionEvent event) {
        Animation shake = AnimationUtils.loadAnimation(ViewReadingActivity.this, R.anim.shake);
        imgAries.startAnimation(shake);

        Intent intent = new Intent(ViewReadingActivity.this, ShowHoroActivity.class);
        startActivity(intent);
        return true;
    }   

問題在於動畫在呈現新活動之前不會運行完成,並且動畫將繼續從其離開的位置開始運行。 有沒有更好的方法可以做到這一點?

這樣使用,您可以擁有動畫列表器

shake.setAnimationListener(new AnimationListener() {

    @Override
    public void onAnimationStart(Animation arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationRepeat(Animation arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationEnd(Animation arg0) {
       Intent intent = new Intent(ViewReadingActivity.this, ShowHoroActivity.class);
    startActivity(intent);

    }
});

為此:1.animation.setAnimationListener(),實現方法2.onanimationend方法,編寫代碼以開始新的活動

我晚:(

動畫偵聽器已包含名為onAnimationEnd的方法@在您的imgAries動畫偵聽器上覆蓋它

onAnimationEnd(Animation anim){
//Start you Activity here using Intent
Intent i=new Intent(this,//Your next Activity);
startActivity(i);

 }

知道了...現在,您可以轉到“動畫結束”的“下一個活動”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM