本文實例講述了Android TextView實現垂直滾動效果的方法。分享給大家供大家參考,具體如下:
在TextView中,如果文本很長,可能需要實現垂直滾動顯示文本的效果。這里需要在XML布局文件中為TextView設置如下幾個屬性。
Android:scrollbars="vertical"android:scrollbarStyle="X"
其中X為outsideOverlay或insideOverlay。
android:scrollbarFadeDuration="X"
其中X表示滾動條從出現到消失的時間,單位是毫秒。
下面是一個完整的XML代碼例子。
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="false" android:maxLines="8" android:background="#FFF" android:textColor="#000" android:textSize="20dp" android:layout_margin="10dp" android:scrollbars="vertical" android:text="@string/big_text" android:scrollbarStyle="outsideOverlay" android:padding="10dp" android:scrollbarFadeDuration="2000" /></LinearLayout>
運行效果如下圖。

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android滾動條與滾動操作技巧總結》、《Android圖形與圖像處理技巧總結》、《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
新聞熱點
疑難解答