How to slide an ImageView from left to right smoothly in Android?

前端 未结 7 1663
小鲜肉
小鲜肉 2021-02-01 21:37

I need to make an ImageView slide from left to right of the screen with a smooth animation (I want the ImageView to be visible during the transition) I

7条回答
  •  死守一世寂寞
    2021-02-01 21:55

    Hope this works for u

    animation.xml

        
    
        
    
    
    

    Animation.java

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.animation.TranslateAnimation;
    import android.widget.ImageView;
    
    public class Animation extends Activity {
    
     @Override
     protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.);
    
      ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
    
      TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
        0.0f, 0.0f);
      animation.setDuration(5000);
      animation.setRepeatCount(5);
      animation.setRepeatMode(2);
      animation.setFillAfter(true);
      img_animation.startAnimation(animation);
    
     }
    }
    

提交回复
热议问题