簡體   English   中英

如何通過“按鈕單擊”暫停活動?

[英]How to Pause an activity with Button Click?

我想通過單擊按鈕暫停動畫活動,這里我有一個球從上到下動畫落下。 我想要一個按鈕“停止”,它會暫停下降並記錄其x,y位置。

您可以在球動畫中添加條件,以便

while(buttonPressed == false && //whatever other code you need for the animation to run)
{
    //button animation code here
}

然后在其后有一個if語句,條件是如果buttonPressed為true,則將記錄球的位置。 您可以使用添加到停止按鈕的動作偵聽器將buttonPressed布爾值設置為true。

首先說:

    AnimatorSet set;
    img_logo = (ImageView) findViewById(R.id.img_logo);
    set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.anim.flipping);
    set.setTarget(img_logo);
    set.start();

在按鈕上單擊:

set.stop();

我認為這也可以幫助您-> http://android-er.blogspot.in/2012/01/start-and-stop-frame-animation-with.html

暫無
暫無

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

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