gpt4 book ai didi

java - 如何将 ImageView 移至顶部?

转载 作者:行者123 更新时间:2023-12-01 12:53:50 24 4
gpt4 key购买 nike

我正在制作这个简单而酷炫的动画。并使用这个问题 - How to spin an android icon on its center point?我的图标可以旋转。但旋转后我希望将 ImageView 向上移动。我怎样才能实现这个目标?

我使用此代码向上移动 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);

问题是,当我添加代码时, ImageView 向上移动,但随后又回到原来的位置,旋转动画也停止。我的完整类(class)如下 -

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);
}
}

问题是,打开应用程序时如何做到这一点。图像旋转然后停止,然后图像向上移动。

最佳答案

您必须为两个动画调用 setFillAfter(true) 方法,如有必要,请在动画结束后更改 imageview 的布局参数,然后失效一次。

关于java - 如何将 ImageView 移至顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24031712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com