动画后,按钮消失了?
After animation, button disappeared?
我有一个屏幕,您可以在其中按 "Generate" 按钮为自己生成每日报价,当您单击该按钮时,将播放一个动画,然后您将进入另一个 activity.另一个名为activity的"Szabaly"会给你一个随机文本,然后你可以按返回按钮,你可以回到activity,在那里你可以按"Generate"按钮。
问题是,当我点击 "Generate" 按钮时,动画开始播放,我到达 "Szabaly" activity 没有任何问题,但我很快按后退按钮,我将找不到我的 "Generate" 按钮。它消失了。也许我必须以某种方式重置动画(状态?)?并将其设置为第一帧?如果你明白我的意思...
我想编写我的应用程序代码,知道一旦我到达 activity,您可以在其中单击生成按钮,将动画重置为第一帧,并能够播放它每次,当我进入 activity 并点击它时。
这是我的代码。
public void onClick(View v) {
YoYo.with(Techniques.ZoomOut).duration(700)
.withListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
input.setText(null);
Intent myIntent = new Intent(MainActivity.this, Szabaly.class);
startActivity(myIntent);
}
我使用了这个库:Android ViewAnimations
您可以使用下面的代码,在这段代码中您还可以在xml中设置fillAfter、duration、zooming value、repeat等动画参数。你也可以用同样的方法从 xml 创建其他动画。
View view = findViewById(R.id.viewLL);
Animation zoomOutAnimation = AnimationUtils.loadAnimation(this,
R.anim.zoom_out);
// set animation in listener
zoomOutAnimation .setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// copy all file before start animation
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation arg0) {
// move to next activity
}
});
view .startAnimation(zoomOutAnimation );
anim/zoom_out.xml :
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="400"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.0"
android:toYScale="0.0" />
YOYO 不支持'fillafter'属性。对于您的视图,在动画结束操作后再次执行类似的操作:YoYo.with(Techniques.ZoomIn).duration(1).playOn(animated_view);
我有一个屏幕,您可以在其中按 "Generate" 按钮为自己生成每日报价,当您单击该按钮时,将播放一个动画,然后您将进入另一个 activity.另一个名为activity的"Szabaly"会给你一个随机文本,然后你可以按返回按钮,你可以回到activity,在那里你可以按"Generate"按钮。
问题是,当我点击 "Generate" 按钮时,动画开始播放,我到达 "Szabaly" activity 没有任何问题,但我很快按后退按钮,我将找不到我的 "Generate" 按钮。它消失了。也许我必须以某种方式重置动画(状态?)?并将其设置为第一帧?如果你明白我的意思...
我想编写我的应用程序代码,知道一旦我到达 activity,您可以在其中单击生成按钮,将动画重置为第一帧,并能够播放它每次,当我进入 activity 并点击它时。
这是我的代码。
public void onClick(View v) {
YoYo.with(Techniques.ZoomOut).duration(700)
.withListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
input.setText(null);
Intent myIntent = new Intent(MainActivity.this, Szabaly.class);
startActivity(myIntent);
}
我使用了这个库:Android ViewAnimations
您可以使用下面的代码,在这段代码中您还可以在xml中设置fillAfter、duration、zooming value、repeat等动画参数。你也可以用同样的方法从 xml 创建其他动画。
View view = findViewById(R.id.viewLL);
Animation zoomOutAnimation = AnimationUtils.loadAnimation(this,
R.anim.zoom_out);
// set animation in listener
zoomOutAnimation .setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// copy all file before start animation
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation arg0) {
// move to next activity
}
});
view .startAnimation(zoomOutAnimation );
anim/zoom_out.xml :
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="400"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.0"
android:toYScale="0.0" />
YOYO 不支持'fillafter'属性。对于您的视图,在动画结束操作后再次执行类似的操作:YoYo.with(Techniques.ZoomIn).duration(1).playOn(animated_view);