Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 開發:為 TextView 加上捲軸

編輯:關於 Android 程式設計

想讓 TextView 支援捲動其實非常簡單,只要把它放進 ScrollView 這個容器標籤裡就可以了。當文字內容超過可視範圍時,ScrollView 便會自動提供垂直方向的捲軸。

[html]
<ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content">
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/txtViewHtml" />
</ScrollView>

要留意的是,ScrollView 一次只能容納一個直接子元素,因此並不適合用來包裹多個並排的元件。如果你的內容很長,記得把 TextView 的 layout_height 設為 wrap_content,讓它能依內容撐開,捲軸才會正常運作。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved