將整個佈局的根視圖包裹在 <ScrollView> 中,即可實現垂直滾動;水平滾動用 <HorizontalScrollView>。
<ScrollView
xmlns:android="https://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"> <!-- 隱藏滾動條 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- 這裡放置原本的所有內容 -->
</LinearLayout>
</ScrollView>
| 屬性 | 說明 |
|---|---|
android:scrollbars="none" | 隱藏滾動條(垂直/水平) |
android:fillViewport="true" | 內容不滿螢幕時也撐滿,避免底部空白 |
android:overScrollMode="never" | 禁用過度滾動邊緣光暈效果 |
NestedScrollView + recyclerView.setNestedScrollingEnabled(false)。