试图将一个按钮到另一点在屏幕上按钮、屏幕上

2023-09-04 05:38:34 作者:多余的暧昧

我试图将3个按键相对于他们的出发点:

I am trying to move 3 buttons relative to their starting points:

在code用于启动动画是:

The code for starting the animation is:

protected void showMoreBtns() {
    Button btn1 = (Button)this.findViewById( R.id.more1btn );
    Button btn2 = (Button)this.findViewById( R.id.more2btn );
    Button btn3 = (Button)this.findViewById( R.id.more3btn );

    Animation showMore = AnimationUtils.loadAnimation( this, R.anim.optionsinup1 );
    btn1.startAnimation( showMore );

    showMore = AnimationUtils.loadAnimation( this, R.anim.optionsinup2 );
    btn2.startAnimation( showMore );

    showMore = AnimationUtils.loadAnimation( this, R.anim.optioninup3 );
    btn3.startAnimation( showMore );
}

和动画的定义是:

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:toXDelta="-60"
        android:toYDelta="-30" />
</set>

这三个动画遵循相同的格式,只有机器人:toDelta 的被修改

的问题是动画运行,然而这些按钮返回到它们原来的位置在动画结束。我希望他们留在终点。

The issues is the animation runs, yet the buttons return to their original position at the end of the animation. I would like them to stay at the end point.

推荐答案

showMore.setFillAfter(真正的); 这将被放置在你的java code。 我希望这将是工作。如果你想用你的布局中使用完整的动画后,你将放在onAnimationEnd按钮(动画动画)在那个地方的按钮。

showMore.setFillAfter(true); This will be placed in your java code. I hope it will be work.If you want to use the button after complete animation you will placed onAnimationEnd(Animation animation) in that place the button using your layout.