2011年2月10日 星期四

[Android] ScrollView使用範例

ScrollView的功能就跟scroll pane一樣,但是ScrollView 只能做垂直滾動,而它的用法很簡單!
首先我們打開main.xml,然後把想要有scroll pane的範圍,包進<ScrollView>裡面。

例如:
<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/>
<EditText/>

</LinearLayout>
</ScrollView>

把需要用到scroll pane的部分寫在 ScrollView標籤裡面就可以了。

android:layout_height="200px",這邊設定"200px"是指高度總長200 pixel(象素) 的意思,超過的部份,就會以滾動的方式呈現。

如果不想要看到ScrollView的滾動條的話,可以在ScrollView裡面多增加一行程式碼:

android:scrollbars="none"
這樣子滾動條就看不見了。

ScrollView只能垂直滾動,如果想要使用水平滾動的話,
就需要使用<HorizontalScrollView>
他們兩者的使用方式是一樣的。

沒有留言:

張貼留言