简体   繁体   中英

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? 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.

  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,然后使它们无效一次。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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