How can I change the width/thickness of a scrollbar?
Asked Answered
P

3

34

Currently this is my scrollbar.xml file:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <gradient
        android:angle="45"
        android:centerColor="@color/blue"
        android:endColor="@color/blue"
        android:startColor="@color/blue" />

    <corners android:radius="8dp" />

</shape>

And this is my ScrollView:

<ScrollView
    android:id="@+id/scrollView1"
    android:scrollbarThumbVertical="@drawable/scrollbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/btnBack" >

This is the scrollbar it gives me. It's good, except it's too thick and obvious. It may not look thick in this screenshot, but it really is.

enter image description here

Am I able to set a ScrollView property to adjust the width/thickness of the scrollbar? Or can I put a property in my gradient?

Puisne answered 26/12, 2013 at 9:41 Comment(3)
Have you tried reducing the size of radius ?Staciestack
@Staciestack the radius determines the roundness on the top and bottom of the scrollbar. Not the width of the scrollbar. But yes I've tried anyways.Puisne
You may wanna take a look at thisRodolforodolph
R
78

add the following property to your layout

android:scrollbarSize="50dip"
Rangefinder answered 26/12, 2013 at 9:51 Comment(0)
B
9

see the android:scrollbarSize="" attribute of ScrollView.

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/btnBack"
    android:scrollbarSize="4dp"
    android:scrollbarThumbVertical="@drawable/scrollbar" >
Brettbretz answered 26/12, 2013 at 9:51 Comment(3)
Perfect size even lol. I asked this in a comment on another post and Dehan said he would answer if I posted a question. I'll accept his, but I'll browse through your previous questions/answer and give you some votes. Thanks.Puisne
@mikeyaworski Really glad to help you... but don't upvote other answers of me as a result of this answer... (really I don't like that way) If it helped you, you can upvote this. and thank youBrettbretz
Sure, just wanted to pass on reputation where it's deserved.Puisne
R
3

For making very easy and using many times, same type of scrollbar in list view, use as a style and color in style.xml and color.xml in values folder.

i.e. in Android Studio :

Project_Name/app/main/res/values

and the code in

style.xml

 <resources>    
   <style name="mScrollBar">
     <item name="android:scrollbarSize">1dp</item>
     <item name="android:scrollbarThumbVertical">@color/base_color</item>
   </style>
 </resources>

in color.xml

 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <color name="Salmon">#FA8072</color>
 </resources>
Richert answered 11/2, 2015 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.