How to move an image from left to right in android

后端 未结 4 1431
余生分开走
余生分开走 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:26

    I am a bit late to the party but worth answering here,

    case 1:

    if your view is at the left side of the screen and you want to move from left edge to right edge then use this:

    imageView.animate()
                .translationX(((rootLayout.width - (imageView.width))).toFloat())
                .setInterpolator(AccelerateInterpolator()).duration = 1500
    

    case 2: If your view is at the center of the screen and you want to move from center to right edge then use this:

    imageView.animate()
                .translationX(((rootLayout.width - (imageView.width)) / 2).toFloat())
                .setInterpolator(AccelerateInterpolator()).duration = 1500
    

    NOTE: rootLayout is root view of your XML

提交回复
热议问题