【发布时间】:2017-04-22 11:55:40
【问题描述】:
我正在尝试提高和降低按钮单击时自动滚动文本的速度,但我不知道如何做到这一点。我试图声明一个默认速度并通过使用一个按钮来增加和减少它的值,但这没有用。 任何帮助都会很棒。请帮助我
ScrollTextView.java:
public class ScrollTextView extends TextView {
public float DEFAULT_SPEED = 9.0f;
public Scroller scroller;
public float speed = DEFAULT_SPEED;
public boolean continuousScrolling = true;
public ScrollTextView(Context context) {
super(context);
scrollerInstance(context);
}
public ScrollTextView(Context context, AttributeSet attributes) {
super(context, attributes);
scrollerInstance(context);
}
public void scrollerInstance(Context context) {
scroller = new Scroller(context, new LinearInterpolator());
setScroller(scroller);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (scroller.isFinished()) {
scroll();
}
}
public void scroll() {
int viewHeight = getHeight();
int visibleHeight = viewHeight - getPaddingBottom() - getPaddingTop();
int lineHeight = getLineHeight();
int offset = -1 * visibleHeight;
int distance = visibleHeight + getLineCount() * lineHeight;
int duration = (int) (distance * speed);
scroller.startScroll(0, offset, 0, distance, duration);
}
public void setSpeed(float speed) {
this.speed = speed;
}
public float getSpeed() {
return speed;
}
public void setContinuousScrolling(boolean continuousScrolling) {
this.continuousScrolling = continuousScrolling;
}
public boolean isContinuousScrolling() {
return continuousScrolling;
}
【问题讨论】:
-
有人请帮助...寻求解决方案
标签: java android autoscroll