我正在尝试实现一个自动滚动的单行文本视图.但我不幸的是无法让它发挥作用.AutoScrollTextView在LinearLayout(width和height = fill_parent)中声明.该类基本上使用一个Handler,它调用自己按给定的量滚动.我已将代码简化为仅显示应每秒滚动5个像素的文本视图.
日志输出正确,getScrollX()方法返回相应的scrollX位置.
如果我不打电话requestLayout(),就不会有任何吸引力.invalidate()没有效果.
有人会有线索吗?
public class AutoScrollTextView extends TextView {
public AutoScrollTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setSingleLine();
setEllipsize(null);
setText("Single-line text view that scrolls automatically if the text is too long to fit in the widget");
}
// begin to scroll the text from the original position
public void startScrolling() {
scrollHandler.sendEmptyMessage(0);
}
private Handler scrollHandler = new Handler() {
private static final int REFRESH_INTERVAL = 1000;
public void handleMessage(Message …Run Code Online (Sandbox Code Playgroud)