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

前端 未结 7 1651
小鲜肉
小鲜肉 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 22:04

    Try this. It will animate the imageview.

            ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
            Display display = getWindowManager().getDefaultDisplay();
            float width = display.getWidth();
            TranslateAnimation animation = new TranslateAnimation(0, width - 50, 0, 0); // new TranslateAnimation(xFrom,xTo, yFrom,yTo)
            animation.setDuration(1000); // 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
    

提交回复
热议问题