How to move an image from left to right in android

后端 未结 4 1422
余生分开走
余生分开走 2020-11-30 00:56

I\'d like to translate an image from left to right on emulator using android animation. I\'m new to android animation. How could I do that?

Thanks.

4条回答
  •  眼角桃花
    2020-11-30 01:08

    Move an image from left to right and right to left by using Android TranslateAnimation

    enter image description here

    ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
    
        TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
                0.0f, 0.0f);          //  new TranslateAnimation(xFrom,xTo, yFrom,yTo)
        animation.setDuration(5000);  // animation duration 
        animation.setRepeatCount(5);  // animation repeat count
        animation.setRepeatMode(2);   // repeat animation (left to right, right to left )
        //animation.setFillAfter(true);      
    
        img_animation.startAnimation(animation);  // start animation 
    

    you can find more details from here

提交回复
热议问题