简体   繁体   English

如何将图像视图移到顶部?

[英]How to move an image view to top?

I was making this simple and cool looking animation. 我正在制作这个简单又酷的动画。 And using this question - How to spin an android icon on its center point? 并使用此问题- 如何在其中心点旋转android图标? I got my icon to rotate. 我的图标旋转了。 But after the rotation I wish to move the image view upwards. 但是旋转之后,我希望将图像视图向上移动。 How can I achieve this? 我该如何实现?

I'm using this code to move the imageview upwards. 我正在使用此代码将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);

The problem is that when I add the code, the image view moves up but then goes back to the spot it was in, also the rotation animation stops. 问题是,当我添加代码时,图像视图会向上移动,然后返回到它所在的位置,旋转动画也会停止。 My full class below - 我的全班以下-

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

Question is, how can I make it that, when opening app. 问题是,打开应用程序时如何做到这一点。 the image rotates and then stops, and then the image is then moved up. 图像旋转然后停止,然后图像向上移动。

您必须为两个动画都调用setFillAfter(true)方法,如果需要,请在动画结束后更改imageview的layoutparams,然后使它们无效一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM