Android 如何通过单击按钮暂停活动?

Android 如何通过单击按钮暂停活动?,android,Android,我想暂停一个按钮点击动画活动,在这里我有一个球是从上到下的动画下降。我想要一个按钮停止,暂停中间的下降,并记录其x,y位置 可以在球动画中添加条件,以便 while(buttonPressed == false && //whatever other code you need for the animation to run) { //button animation code here } 然后在它后面有一个if语句,条件是如果按下的按钮为true,则会记录球的位置

我想暂停一个按钮点击动画活动,在这里我有一个球是从上到下的动画下降。我想要一个按钮停止,暂停中间的下降,并记录其x,y位置

可以在球动画中添加条件,以便

while(buttonPressed == false && //whatever other code you need for the animation to run)
{
    //button animation code here
}
然后在它后面有一个if语句,条件是如果按下的按钮为true,则会记录球的位置。您可以使用添加到“停止”按钮的操作侦听器将buttonPressed boolean设置为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();

我认为这也可以帮助你-->

这实际上取决于球的动画方式。创建一种方法来停止小球下落的动画。并在单击按钮时调用该方法。