How to create a marquee effect for a text of smaller length not exceeding the screen size in Android?

前端 未结 5 1059
走了就别回头了
走了就别回头了 2020-12-03 16:18

I have been trying to give the marquee effect for the word HELLO in my application but android does not allow the same unless the length of the text exceeds the screen size.

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 16:46

    To apply tickr/marquee animation on text view(even for short text length), it creates an translatory animation from extreme right(+1f) to extreme left(-1f) and then restarts the animation.

    public void setTickerAnimation(View view) {
        Animation animation = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, +1f,
                Animation.RELATIVE_TO_SELF, -1f,
                Animation.RELATIVE_TO_SELF, 0f,
                Animation.RELATIVE_TO_SELF, 0f);
        animation.setRepeatCount(Animation.INFINITE);
        animation.setRepeatMode(Animation.RESTART);
        animation.setInterpolator(new LinearInterpolator());
        animation.setDuration(4000);
        view.startAnimation(animation);
    }
    

提交回复
热议问题