Hide scrollbar in ScrollView

2019-01-22 11:41发布

问题:

I have an app with a ScrollView, and I don't want the scrollbar to appear on the screen. How can I hide the scrollbar in a ScrollView while making sure scrolling still works?

回答1:

In Java add this code

myScrollView.setVerticalScrollBarEnabled(false);
myScrollView.setHorizontalScrollBarEnabled(false);

In XML add following attribute to your ScrollView

android:scrollbars="none"

Like this

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainScroll"
android:scrollbars="none" <!-- line to be added -->
>


回答2:

This will hide the Scroll bar stick but scroll bar is not disable

android:scrollbarThumbVertical="@null"

android:scrollbarThumbHorizontal="@null"

This will disable the scroll bar

android:scrollbars="none"


回答3:

In XML set android:scrollbars="none"



回答4:

Try this, it is also working...

android:scrollbarThumbVertical="@null"

or

android:scrollbarThumbHorizontal="@null"


回答5:

In the XML layout, add this property:

android:scrollbarSize="0dp"


回答6:

For hiding a vertical scrollbar, do this in the XML:

android:scrollbarThumbVertical="@null"

And for Hiding horizontal scrollbar do this :

android:scrollbarThumbHorizontal="@null"

The above lines of codes will work if you want to hide the scrollbar without disabling it.

And for disabling a scrollbar, write this:

android:scrollbars="none"


回答7:

In my experience,

android:scrollbarThumbVertical="@null"

can cause NullPointerException in older devices. Use this instead:

android:scrollbarThumbVertical="@android:color/transparent"

Cheers!