最近项目需要一个逐字展示的文本控件,由于没有找到适合的,便随手写了一个,不废话直接上代码。
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.Nullable;
/**
* 逐字显示的文本控件
* @author pinkman
* @version 1.1 2022/5/31
*/
@SuppressLint("AppCompatCustomView")
public class GraduallyTextView extends TextView {
private float drawLength = 0; //已显示的长度
public GraduallyTextView(Context context) {
this(context, null);
}
public GraduallyTextView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public GraduallyTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
/**
* 在某个时间段显示出所有文本
* @param text 要显示的文本
* @param duration 显

最低0.47元/天 解锁文章
5792

被折叠的 条评论
为什么被折叠?



