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

Android ScrollView 用法解析

編輯:關於 Android 程式設計

ScrollView 概念

ScrollView 是滾動視圖,當畫面內容過多、無法一次顯示時,可透過垂直滾動來瀏覽。ScrollView 只支援垂直滾動。

版面配置

<ScrollView xmlns:android="https://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical">

    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/p1"
            android:layout_gravity="center_horizontal"/>

    </LinearLayout>
</ScrollView>

使用時應注意 ScrollView 通常只能包含一個直接子元件,若內容較複雜,可先放入 LinearLayout 或其他版面容器。

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