gpt4 book ai didi

java - 单击按钮时增加和减少自动滚动文本速度

转载 作者:行者123 更新时间:2023-12-02 02:52:46 25 4
gpt4 key购买 nike

我正在尝试增加和减少按钮单击时自动滚动文本的速度,但我不知道如何做到这一点。我尝试声明默认速度并通过使用按钮来增加和减少其值,但这不起作用。任何帮助都会很棒。请帮助我

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;
}

最佳答案

看看这个Marquee Set Speed

如果您想提高滚动速度,则降低以下值:

private int mRndDuration = 10000;//reduce the value of mRndDuration to increase scrolling speed

关于java - 单击按钮时增加和减少自动滚动文本速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43558915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com