2010-11-26 102 views
3

我已经使用了滚动条进行自动滚动,但即使文本结束,滚动条仍然保持滚动状态。我想找到位置,并且想要自动停止滚动,所以当文本滚动文本时,文本会到达其初始位置。我怎样才能做到这一点?如何在textview中实现Scroller进行自动滚动?

用于自动滚动的代码是:

public void Scroll() 
{ 
    //text = (TextView) findViewById(R.id.TxtView); 
    length = text.getLineCount(); 
    scroll.computeScrollOffset(); 
    text.setScroller(scroll); 
    int a = text.getBottom(); 
    int b = text.getTop(); 
    //scroll.extendDuration(scroll.getFinalY()); 
    scroll.startScroll(scroll_x, scroll_y, 0, a, (500000)/ speedAmount);  
} 

回答

1

尼克

您需要检查源代码here

再次文本必须涉及到其初始位置

这种用途scrollTo(0, 0);

我想找到的位置

使用scroll.getCurrX();

要停止自动滚动

使用scroll.abortAnimation();

&你做:)

编辑:!

尼克,我写了从Android.Widget.TextView派生的类定制TextView文本可以滚动,直到文本完成&完成文本回到初始position.All你ne ED要做的就是创建定义here &只是覆盖computeScroll()如下

public void computeScroll() { 
super.computeScroll(); 

if (null == mSlr) return; 

if (mSlr.isFinished() && (!mPaused)) { 
scrollTo(0, 0);//scroll to initial position or whatever position you want it to scroll 
} 
} 
+0

对不起,我已经使用了这些方法,但这不是这样......我在找什么 – Nikki 2010-11-29 09:22:02

+0

@Nikki你的意思是只滚动一次吗?您可以使用scroll.isFinished()检查滚动文本是否完成,然后是scroll.abortAnimation()。我希望我在帮助你方面是正确的。 – 100rabh 2010-11-29 09:56:18

相关问题