1. 程式人生 > >ScrollView和HorizontalScrollView的使用

ScrollView和HorizontalScrollView的使用

基本的佈局,當佈局裡面的內容超過螢幕大小的時候,是不會顯示螢幕之外的東西的.這時候要想顯示佈局裡所有的資訊,就必須利用ScrollView和HorizontalScrollView來實現,其實這個實際上就是為佈局容器增加了豎向或者橫向滾動條.使用ScrollView和HorizontalScrollView時,必須要注意,這個兩個元素只能有一個子元素,並且這個子元素要是一個佈局容器.這個兩個元素可以相互巢狀.

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
  
           
        </LinearLayout>
    </ScrollView>
</HorizontalScrollView>

一般使用垂直滾動條的時候,就用線性佈局的豎直方向排列控制元件.使用水平滾動條時,控制元件的排列一般要是在水平方向上.