我想通過在其上設置滾動條來實現一種垂直滾動TextView。以下代碼適用於運行Android 2.3的設備,但不適用於運行Android 15級設備。任何想法爲什麼?在TextView上設置滾動條以進行垂直滾動
Private TextView tenthsTxt;
Private Scroller tenthsScroller;
....
tenthsTxt = (TextView)findViewById(R.id.tenths);
LinearInterpolator scrollerInterpolator = new LinearInterpolator();
tenthsScroller = new Scroller(this, scrollerInterpolator);
tenthsTxt.setScroller(tenthsScroller);
tenthsScroller.startScroll(0,0,0, 59);
tenthsTxt.invalidate();
....
爲TextView的中的XML看起來是這樣的:
<TextView
android:id="@+id/tenths"
android:background="@drawable/tenths_digit_holder"
android:text="0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0"
android:textSize="25dp"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom= "5dp"
android:layout_width = "30dp"
android:textStyle="normal"
android:layout_height="43dp"
android:textColor="#ffff0000" />
在Android 2.3 TextView的垂直滾動通過正確的金額。在運行4.03的Android設備上,TextView根本不滾動。可以肯定的是,還使用了縮放到pixelDensity設備的y位移 - 結果與在Android 4.03設備上沒有觀察到滾動移動相同。
我不是100%肯定你正在嘗試做的,你想這個文本自動滾動向上/向下像在電影中得分? – 2013-03-23 00:10:41
感謝您的回覆。這是一個簡單的測試,我用它來評估TextView垂直滾動其內容59個像素的能力。這個測試在onCreate()函數中調用。該應用程序稍後使用tenthsScroller.startScroll(0,0,0,y),其中y是一個計算值。測試和稍後在應用程序中對tenthsScroler.startScroll的調用不顯示Android 4.03上的任何滾動,但在Android 2.3上正常工作。在回答你的問題時,是的,它應該像電影中的信用一樣滾動,但由於我沒有設置持續時間,所以滾動應該是瞬間的。 – user1608385 2013-03-23 00:29:18