安卓_神坑的scrollbarSize

博客讲述了在安卓开发中遇到scrollbarSize属性不起作用的问题,指出这其实是一个系统bug。作者分享了如何通过查阅资料找到问题原因,View.java文件中的错误导致设置无效。并暗示存在一种解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


 今天需要求改下scrollbar的大小.觉得他太长过了.不好看..

 就在属性里面添加多

 android:scrollbarSize="20DP"这么一段


<ScrollView

        android:id="@+id/scrollView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"  

        android:scrollbarSize="20px"

        android:scrollbars="vertical" >

       android:scrollbarSize="20dp"

</ScrollView>


但发现没效果呀.坑爹啊.然后搜索下.得到这么个连接. https://code.google.com/p/android/issues/detail?id=14317

 内容如下:后面有翻译

For example, in case of the following tag in xml layout, android:scrollbarSize is ignored.
<ScrollView
	android:layout_width="wrap_content" android:layout_height="fill_parent"
	android:fadeScrollbars="false"
	android:scrollbarThumbVertical="@drawable/thumb01"
	android:scrollbarSize="20px"
>

For your information, drawable/thumb01.xml is the following for example.
<shape xmlns:android="http://schemas.android.com/apk/res/android">
	<solid android:color="#FF0000"/>
	<corners android:radius="4px"/>
</shape>

But it works well when android:scrollbarThumbHorizontal attribute is added in the same ScrollView tag.
For example below.
<ScrollView
	android:layout_width="wrap_content" android:layout_height="fill_parent"
	android:fadeScrollbars="false"
	android:scrollbarThumbVertical="@drawable/thumb01"
	android:scrollbarThumbHorizontal="@drawable/thumb01"
	android:scrollbarSize="20px"
>

Of course, android:scrollbarThumbHorizontal means nothing in this case.

I believe that this problem is caused by View class of android.view package.

Hereinafter, the target version is Android 2.3 (Gingerbread). 

The problem is in source code of View.java, several lines from 5940 line.
The "size" variable is the size of "horizontal" scrollbar of 5940 line.
But, this variable seems to be used as the size of "vertical" scrollbar at 5972 and 5974 lines.
It is necessary to get the size of vertical scrollbar before 5972 line, is it ?


就是说.他发现要同时添加多这么两行后.才有用.
        android:scrollbarThumbVertical="@drawable/thumb01"
	android:scrollbarThumbHorizontal="@drawable/thumb01"

为啥呢?这是安卓系统里面一个bug. 在View.java这个文件里面 .没搞好.设置错了.


解决方案:

<ScrollView
	android:layout_width="wrap_content" android:layout_height="fill_parent"
	android:fadeScrollbars="false"
	android:scrollbarThumbVertical="@drawable/thumb01"
	android:scrollbarThumbHorizontal="@drawable/thumb01"
	android:scrollbarSize="20px"
>


thumb01.xml长这样的:

 <shape xmlns:android="http://schemas.android.com/apk/res/android">
	<solid android:color="#FF0000"/>
	<corners android:radius="4px"/>
</shape>
上面这个方案实测有用.!!!!




然后还搜到另外一个方案:
 在Res /values/Styel里面加多这个Style.然后设置scrollbar为这个style.....我试了.没鸟用.
你们自己试下有没用吧

<resources>
   <style name="ShowAllScrollBar1">
     <item name="android:scrollbarSize">20px</item>           
 </style>
</resources>


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值