NestedScrollView 控制滑块大小
时间: 2023-07-18 16:05:49 浏览: 62
可以使用 `android:scrollbarThumbVertical` 和 `android:scrollbarSize` 属性来控制 NestedScrollView 中滚动条的大小和样式。
`android:scrollbarThumbVertical` 控制滑块的样式,可以设置为一个 drawable,比如:
```xml
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarThumbVertical="@drawable/my_scrollbar_thumb">
...
</androidx.core.widget.NestedScrollView>
```
`android:scrollbarSize` 控制滑块的大小,单位是像素,比如:
```xml
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarThumbVertical="@drawable/my_scrollbar_thumb"
android:scrollbarSize="8dp">
...
</androidx.core.widget.NestedScrollView>
```
其中,`my_scrollbar_thumb` 是一个自定义的 drawable,可以在它的 `shape` 中定义滑块的样式。比如:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="16dp" />
<solid android:color="#ff0000" />
</shape>
```
这个 drawable 定义了一个高度为 16dp,颜色为红色的矩形滑块。