我想知道如何在特定页面上回归后重复制作动画。当您访问某个活动时,我的动画基本上会将RelativeLayout向下翻译几个像素。但是,如果我然后单击一个按钮将我发送到另一个页面,然后点击后退按钮返回,则TranslationAnimation不会再次启动。
这是代码:
RelativeLayout r1;
r1 = findViewById(R.id.r1);
TranslateAnimation a = new TranslateAnimation(0,0,-10f,0);
a.setDuration(800);
a.setFillAfter(true);
r1.startAnimation(a);
我每次访问活动时如何重新启动此动画?
在活动中制作单独的方法
void myanimation(){
TranslateAnimation a = new TranslateAnimation(0,0,-10f,0);
a.setDuration(800);
a.setFillAfter(true);
r1.startAnimation(a);
}
然后调用activityResume中的方法
@Override
public void onResume(){
super.onResume();
myanimation();
}
在你的onResume()方法中使用它。每次与活动互动时都会调用OnResume。