Android 跑马灯是一种常见的文字滚动效果,它可以让文字在屏幕上从左向右滚动,然后从右向左滚动,再从左向右滚动,如此循环。实现 Android 跑马灯的方法有很多,是使用 TextView 和 ObjectAnimator 来实现的代码:
Android 跑马灯是一种常见的文字滚动效果,它可以让文字在屏幕上从左向右滚动,然后从右向左滚动,再从左向右滚动,如此循环。
实现 Android 跑马灯的方法有很多,是使用 TextView 和 ObjectAnimator 来实现的代码:
// 创建 TextView
TextView textView = new TextView(this);
// 设置文字
textView.setText("This is a text scrolling in a loop");
// 设置文字大小
textView.setTextSize(20);
// 设置文字颜色
textView.setTextColor(Color.BLACK);
// 设置文字位置
textView.setX(-1000f);
// 将 TextView 添加到布局中
layout.addView(textView);
// 创建 ObjectAnimator
ObjectAnimator animator = ObjectAnimator.ofFloat(textView, "x", -1000f, 1000f);
// 设置动画时间
animator.setDuration(3000);
// 设置重复次数
animator.setRepeatCount(ObjectAnimator.INFINITE);
// 启动动画
animator.start();
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(67条)