安卓_神坑的scrollbarSize

来源:互联网 发布:淘宝女装代销选货技巧 编辑:程序博客网 时间:2024/04/29 14:21


 今天需要求改下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.<ScrollViewandroid: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.<ScrollViewandroid: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这个文件里面 .没搞好.设置错了.


解决方案:

<ScrollViewandroid: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>


0 0
原创粉丝点击