本例介紹了ScrollView 的幾種風格,android:scrollbarStyle 用來定義捲軸的風格和位置,捲軸位置可以為”overlaid”或是”inset”,當使用”inset” 風格時,捲軸添加到View的Padding地區。捲軸可以顯示在View的Padding地區內或是在View的邊緣。
scrollbarStyle 有如下幾種風格:
insideOverlay inside the padding and overlaid
insideInset inside the padding and inset
outsideOverlay Edge of the view and overlaid
outsideInset Eged of the view and inset
本例的XML
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”>
<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:orientation=”horizontal”>
<ScrollView
android:layout_width=”100dip”
android:layout_height=”120dip”
android:background=”#FF0000″>
<LinearLayout
android:orientation=”vertical”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/scrollbar_2_text” />
…
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/scrollbar_2_text” />
</LinearLayout>
</ScrollView>
<ScrollView
android:layout_width=”100dip”
android:layout_height=”120dip”
android:background=”#00FF00″
android:paddingRight=”12dip”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/scrollbar_3_text”
android:textColor=”#000000″
android:background=”#60AA60″ />
</ScrollView>
<ScrollView
android:id=”@+id/view3″
android:layout_width=”100dip”
android:layout_height=”120dip”
android:background=”@android:drawable/edit_text”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:textColor=”#000000″
android:text=”@string/scrollbar_3_text” />
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>
<ScrollView
android:id=”@+id/view4″
android:layout_width=”100dip”
android:layout_height=”120dip”
android:scrollbarStyle=”outsideOverlay”
android:background=”@android:drawable/edit_text”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:textColor=”#000000″
android:text=”@string/scrollbar_3_text” />
</ScrollView>
<ScrollView
android:id=”@+id/view5″
android:layout_width=”100dip”
android:layout_height=”120dip”
android:scrollbarStyle=”outsideInset”
android:background=”@android:drawable/edit_text”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:textColor=”#000000″
android:text=”@string/scrollbar_3_text” />
</ScrollView>
</LinearLayout>
</LinearLayout>