scrollbarStyle属性一共四个属性 outsideInset outsideOverlay insideOverlay insideInset
我们可以拆为2组对比
Inset VS Overlay
scrollbar本身是有宽度的,是否为显示scrollbar预留显示区域(padding),要根据属性判断
Inset会增加padding,Overlay不会增加padding
outside VS inside
outside会将scrollbar显示在padding侧(视觉效果靠右)
inside会将scrollbar显示在ScrollView的子view内部(上面Inset增加的padding也算子view的部分)(视觉效果靠左)
实际demo
scrollbar_vertical_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#3333FF" android:endColor="#8080FF"
android:angle="0"/>
<corners android:radius="6dp" />
</shape>
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#cccc"
android:numColumns="1"
android:paddingEnd="20dp"
android:requiresFadingEdge="vertical"
android:scrollbarStyle="outsideInset"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0f0"
android:text="outsideInset test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text "
android:textColor="#000000" />
</ScrollView>
<ScrollView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#cccc"
android:numColumns="1"
android:paddingEnd="20dp"
android:requiresFadingEdge="vertical"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0f0"
android:text="outsideOverlay text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text "
android:textColor="#000000" />
</ScrollView>
<ScrollView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#cccc"
android:numColumns="1"
android:paddingEnd="20dp"
android:requiresFadingEdge="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0f0"
android:text="insideOverlay text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text "
android:textColor="#000000" />
</ScrollView>
<ScrollView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#cccc"
android:numColumns="1"
android:paddingEnd="20dp"
android:requiresFadingEdge="vertical"
android:scrollbarStyle="insideInset"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0f0"
android:text="insideInset text test text test text test text test text test text test text test text test text test text test text test text test text test text test text test text "
android:textColor="#000000" />
</ScrollView>
</LinearLayout>
效果图

参考link
https://blog.csdn.net/yuzhiqiang666/article/details/7869047
本文详细介绍了Android中scrollView的scrollbarStyle属性的四种设置方式:outsideInset、outsideOverlay、insideOverlay和insideInset,并通过实例展示了不同属性对滚动条显示位置及布局的影响。
3478

被折叠的 条评论
为什么被折叠?



