Android ScrollView Scrollbar Size

2019-04-04 23:15发布

问题:

I'm using a ScrollView and I want to set the ScrollBar size, but everything I tried failed. I tried with attribute android:scrollbarSize, with style, with the theme but nothing. The size of the scrollbar it's always the same. Any suggestions? Thanks

I tried with this:

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_marginTop="10px"
    android:layout_marginBottom="15px"
    android:scrollbarSize="20px"
    android:scrollbarTrackVertical="@drawable/scrollbar_reflection"
    android:scrollbarThumbVertical="@drawable/scrollbar_state2">

but the width of the Scrollbar doesn't change.

So I created a style file like this:

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

and then set style in AndroidManifest.

回答1:

Try implementing android:scrollbarThumbVertical and android:scrollbarSize="1dp" together, and your problem will be solved for ScrollView, RecyclerView.

Refer following code snippet

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_marginTop="10px"
    android:layout_marginBottom="15px"
    android:scrollbars="vertical"
    android:scrollbarThumbVertical="@color/colorPrimaryDark"
    android:scrollbarSize="1dp">

For HorizontalScrollView:

<HorizontalScrollView
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_marginTop="10px"
    android:layout_marginBottom="15px"
    android:scrollbars="horizontal"
    android:scrollbarThumbHorizontal="@color/colorPrimaryDark"
    android:scrollbarSize="1dp">


回答2:

I've actually been struggling with this as well. Unfortunately, it appears that the problem is actually in the Android sourcecode, and will not be fixed until the next Android release. After a bit of searching, I found this info here: http://code.google.com/p/android/issues/detail?id=14317.



回答3:

Have you tried to change the scrollbar drawable to some bigger one?

android:scrollbarThumbHorizontal