直接在 TableLayout 外層包裹 ScrollView 即可實現垂直滾動,但需注意佈局層級。
<ScrollView xmlns:android="https://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="@+id/lunchtableviewing"
android:layout_width="194dp"
android:layout_column="0"
android:layout_columnSpan="4"
android:layout_row="7">
<!-- TableRow 與子視圖 -->
</TableLayout>
</ScrollView>
ScrollView **只能有一個直接子視圖**,故將 TableLayout 作為唯一子項。HorizontalScrollView(或使用單一 ScrollView 配合 android:fillViewport="true")。TableLayout 的 layout_column 等屬性屬於 TableRow.LayoutParams,僅在 TableRow 子視圖上生效。代碼中向 TableLayout 添加 TableRow 即可,滾動自動生效。