【问题标题】:Increasing and decreasing auto-scroll text speed on button click增加和减少按钮单击时的自动滚动文本速度
【发布时间】: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


【解决方案1】:

看看这个Marquee Set Speed

如果你想提高滚动速度然后减少的值:

private int mRndDuration = 10000;//减小mRndDuration的值来提高滚动速度

【讨论】:

  • 我见过这个.....但是它水平滚动。我需要垂直滚动。将它的 Horizo​​ntalscroll 设置为 false 也没有用
  • 已解决.. github.com/ritesh-bhavsar86/StockAutoScroll .. 在按钮上单击 tvcontent.setspeed(tvcontent.getspeed()-);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-12
  • 2021-09-16
  • 1970-01-01
  • 1970-01-01
  • 2019-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多