scrollbarStyle属性

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值