2010-11-26 51 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