閱讀844 返回首頁    go 阿裏雲 go 技術社區[雲棲]


7.1.4 ScrollView結合案例詳解

ScrollView是一個滾動條控件,當屏幕中內容很多時候需要使用滾動條。ScrollView類的繼承圖如下:
java.lang.Object
   ↳android.view.View
   ↳android.view.ViewGroup
   ↳android.widget.FrameLayout
   ↳android.widget.ScrollView
android.widget.ScrollView繼承了android.widget.FrameLayout框架布局類。ScrollView例子如圖7-9所示滾動條例子。
 


圖7-9 Scrollview
布局文件請參考代碼清單7-10,完整代碼請參考chapter7_1工程中scrollview_1.xml代碼部分(chapter7_1/res/layout/scrollview_1.xml)。
【代碼清單7-10】
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:andro
android:layout_width="match_parent" android:layout_height="wrap_content">
<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:text="@string/hello"
android:textSize="20dip" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/content" />
</LinearLayout>
</ScrollView>
ScrollView有很多屬性管理它的樣式,如果在xml中設置,可以在<ScrollView >標簽內設置滾動條樣式的屬性:
• android:scrollbars="none",不顯示滾動條,但能夠滾動的;
• android:scrollbarSize,滾動條大小。
修改上麵的例子添加這些屬性xml布局文件代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:andro
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbarSize="12dip"
    android:scrollbars="none"
    >
<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:text="@string/hello"
android:textSize="20dip" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/content" />
</LinearLayout>
</ScrollView>
                                      出自《Android開發案例驅動教程》第七章

最後更新:2017-04-02 06:51:48

  上一篇:go Android WebView的緩存
  下一篇:go [usaco] 海明碼