我正在制作这个简单而又酷炫的动画。 并使用这个问题 - How to spin an android icon on its center point?我的图标旋转了。但是在旋转之后我希望向上移动图像视图。我怎样才能做到这一点?
我使用此代码向上移动imageview。
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -700);
animation.setDuration(1*1500);
animation.setRepeatCount(0);
ImageButton logo_icon_two = (ImageButton) findViewById(R.id.logo_icon);
logo_icon_two.startAnimation(animation);
问题在于,当我添加代码时,图像视图会向上移动,然后返回到它所在的位置,旋转动画也会停止。我的完整课程如下 -
public class WelcomeActivity extends Activity {
private static final float ROTATE_FROM = 0.0f;
private static final float ROTATE_TO = -10.0f * 360.0f;// 3.141592654f * 32.0f;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_activity);
ImageButton logo_icon = (ImageButton) findViewById(R.id.logo_icon);
RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO);
r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
r.setDuration((long) 1*1500);
r.setRepeatCount(0);
logo_icon.startAnimation(r);
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -700);
animation.setDuration(1*1500);
animation.setRepeatCount(0);
ImageButton logo_icon_two = (ImageButton) findViewById(R.id.logo_icon);
logo_icon_two.startAnimation(animation);
}
}
问题是,打开应用程序时如何才能做到这一点。图像旋转然后停止,然后图像向上移动。
答案 0 :(得分:1)
你必须为你的两个动画调用setFillAfter(true)方法,如有必要,在动画结束后更改imageview的layoutparams然后失效一次。