2010年1月22日星期五

滾動視圖(ScrollView)

滾動視圖(ScrollView)是一個可以滾動的佈局容器, 允許它大於物理顯示. 滾動視圖(ScrollView)是一個框佈局(FrameLayout), 這意味著你應該將一個包含全部滾動內容的子項放進去. 該子項本身可以是一個帶有複雜對象的佈局管理器(layout manager).




例如:
<?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ScrollView
android:layout_height="200px"
android:layout_width="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="
Class Overview\n\n
Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.\n\n
The TextView class also takes care of its own scrolling, so does not require a ScrollView, but using the two together is possible to achieve the effect of a text view within a larger container.\n\n
ScrollView only supports vertical scrolling.\n"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button Inside ScrollView"
/>
</LinearLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button Outside ScrollView"
/>
</LinearLayout>


相關文章: 水平滾動視圖(HorizontalScrollView)



沒有留言:

發佈留言