我如何制作这个滚动条:
问问题
39520 次
2 回答
30
要更改拇指图像,您只需创建以下样式并将其应用于您的 ScrollView:
<style name="your_style_name">
<item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fadeScrollbars">false</item>
<item name="android:scrollbarThumbVertical">@drawable/scroller_thumb</item>
</style>
其中 scroller_thumb 是滚动拇指的自定义图像。
还要注意以下属性:
- "android:fadeScrollbars" 设置为 false 以使拇指图像永久保留。
- “android:scrollbarStyle”设置为 outsideOverlay 以使拇指图像绘制在“视图边缘并覆盖”,如下所述:android:scrollbarStyle
现在,为了将您想要的细线放在滚动条下,只需将包含线条图像的图像视图添加到 ScrollView 的直接子级(RelativeLayout 子级作为 ScrollView 的直接子级将允许您将图像定位在视图的右侧 - 所以这是我的选择)。
就是这样。
于 2013-01-23T19:20:18.953 回答
11
设置 android:scrollbarThumbVertical 不是最好的解决方案,它会根据列表大小拉伸拇指图像...
你最好使用 android:fastScrollThumbDrawable
这是一个例子:
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarSize="0dip"
android:scrollbarStyle="outsideInset"
android:fastScrollAlwaysVisible="true"
android:fastScrollEnabled="false"
android:scrollbars="vertical" />
然后在您添加的 styles.xml AppTheme
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:fastScrollThumbDrawable">@drawable/scroller_style</item>
</style>
并在 res/drawable 文件夹上创建文件:scroller_style.xml 和内容
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/scroller_active" android:state_pressed="true"/>
<item android:drawable="@drawable/scroller"/>
</selector>
其中 scroller 是您的拇指图像,而 scroller_active 是您的活动拇指图像(可选)
于 2013-12-04T20:24:58.250 回答