Android 忽略滚动条大小
我试图修改 ListView 滚动条的宽度,但没有成功
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:scrollbars="vertical"
android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
android:scrollbarSize="4px"
android:clickable="true"/>
首先我尝试使用 4px 宽的可绘制图像,但 .png 的大小已调整。然后我尝试使用从 SamplesApi 中提取的形状,但没有成功。
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40px">
<gradient android:startColor="#505050" android:endColor="#C0C0C0"
android:angle="0"/>
<corners android:radius="0dp" />
我尝试过使用和不使用 android:width 属性。
有一个关于同一主题的问题(Android 中滚动条的宽度),但它没有尝试任何与我已经尝试的不同的东西。据我所知,创建自己的主题不应改变输出。
SamplesApi (Views/ScrollBars) 中有一个示例。我尝试修改scrollbarSize属性但没有结果。
我了解 ninepatch 图像,但有一个属性应该可以满足我的要求。
有什么提示吗?提前致谢。
I'm trying to modify a ListView scrollbar's width without success
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:scrollbars="vertical"
android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
android:scrollbarSize="4px"
android:clickable="true"/>
First I tried using a drawable image 4px wide, but the .png was resized. Then I tried using a shape extracted from SamplesApi, without success.
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40px">
<gradient android:startColor="#505050" android:endColor="#C0C0C0"
android:angle="0"/>
<corners android:radius="0dp" />
I've tried with and without the android:width attribute.
There's a question on the same topic (Width of a scroll bar in android), but it doesn't try anything different that what I'm already trying. As far as I know, creating my own theme shouldn't change the output.
There's an example in SamplesApi (Views/ScrollBars). I tried modifying the scrollbarSize attribute without result.
I know about ninepatch images, but there's an attribute which should do what I want.
Any hint? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的经验,Android 会忽略scrollbarSize,并根据由 android:scrollbarTrackHorizontal 设置的水平滚动轨道可绘制(PNG 图像)的高度来计算两个滚动条的大小。
By my experience, Android ignores scrollbarSize, and computes size of both scrollbars from height of horizontal scroll track drawable (PNG image) which is set by android:scrollbarTrackHorizontal.
您是否尝试过
然后通过形状来确定尺寸?我遇到了类似的问题,我就这样解决了
Did you tried
and then just putting the size thru shape? I had kind of the same problem like this and I solved it in that way