Android 忽略滚动条大小

发布于 2024-08-28 17:28:34 字数 1160 浏览 7 评论 0原文

我试图修改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为你鎻心 2024-09-04 17:28:34

根据我的经验,Android 会忽略scrollbarSize,并根据由 android:scrollbarTrackHorizo​​ntal 设置的水平滚动轨道可绘制(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.

避讳 2024-09-04 17:28:34

您是否尝试过

android:scrollbarSize="wrap_content"

然后通过形状来确定尺寸?我遇到了类似的问题,我就这样解决了

Did you tried

android:scrollbarSize="wrap_content"

and then just putting the size thru shape? I had kind of the same problem like this and I solved it in that way

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文