Andro
Andro

Reputation: 174

How to edit the height of scroll bar in Android widget "ScrollView"?

How can I edit the scroll height in Android "ScrollView"?

enter image description here

Upvotes: 2

Views: 10547

Answers (1)

Muhammed Refaat
Muhammed Refaat

Reputation: 9103

you can't change the height of the ScrollView-bar as it depends on the contents of the ScrollView(like any scroll bar), which means you will have a short one for many contents and a tall one for less contents, but instead you can change the width of vertical scrollbars and height of horizontal scrollbars using android:scrollbarSize="", and there is workaround to achieve that, just control the Height of the scrollView and this will control the Height of it's bar, and to achieve that just refer to this answer.

And when talking about adding a custom image for scroll it can be done using:

android:scrollbarThumbVertical=""

which

Defines the vertical scrollbar thumb drawable

or:

android:scrollbarThumbHorizontal=""

which

Defines the horizontal scrollbar thumb drawable.


Update:

To control the width and height of your scroll bar, add your drawable image to a layer_list with a sized shape and save it as a drawable then use it back:

your_shape.xml:

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

    <item android:drawable="@drawable/your_image">
        <shape
            android:padding="10dp"
            android:shape="rectangle" >
            <size
                android:height="20dp"
                android:width="10dp" />
        </shape>
    </item>

</layer-list>

So, just save it to your drawable folder and add it as a thumb (don't forget to change the width and height I put to something fits according to your needs):

 android:scrollbarThumbHorizontal="R.drawable.your_shape.xml"

Upvotes: 7

Related Questions