Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove scroll bar track from ScrollView in Android

My Android app has a main WebView (HTML loaded from a local resource) which I want to use the entire width of the screen and be able to make (vertically) scrollable. So I've wrapped the WebView in a ScrollView in my layout XML, but no matter what I do I can't seem to be able to remove the scroll bar track from the right side of the scroll view. Even worse, I can't seem to be able to change the background colour of the scroll bar track.

The track takes up about 10dp's or so, which is creating problems for the HTML in the WebView. I'd like the scroll bar to appear on top of the web view (iPhone style, if you know what I mean). Now, you could say "why don't you change your HTML to be 10px thinner?", which is my fallback solution, but I'd much rather not have to.

Here's the relevant snippet of layout XML, you'll see I've tried every android:etc attribute I could find:

<ScrollView    android:id="@+id/deal_web_view_holder"   android:layout_below="@id/clock_bar_holder"   android:layout_width="fill_parent"    android:layout_height="fill_parent"   android:fillViewport="false"   android:fadingEdge="none"   android:background="#02a7e9"   android:scrollbars="none"   android:scrollbarSize="0dp"   android:paddingRight="0dp"   android:scrollbarAlwaysDrawVerticalTrack="false"   android:scrollbarStyle="insideOverlay"   android:scrollbarTrackVertical="@drawable/scrollbar_track_vertical" >     <WebView        android:id="@+id/deal_web_view"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>   </ScrollView> 

I'm targeting platform 2.1 / API lvl 7, really just dealing with normal size displays, mdp, hdp and xhdp.

like image 482
Mick Byrne Avatar asked Jun 08 '11 01:06

Mick Byrne


People also ask

How do I turn off the horizontal scroll bar on Android?

You can also achieve this programatically using methods setVerticalScrollBarEnabled(false) and setHorizontalScrollBarEnabled(false) for your view.


2 Answers

To remove a scrollbar from a view (and its subclass) via xml:

android:scrollbars="none" 

http://developer.android.com/reference/android/view/View.html#attr_android:scrollbars

like image 188
Garzahd Avatar answered Oct 17 '22 04:10

Garzahd


try this is your activity onCreate:

ScrollView sView = (ScrollView)findViewById(R.id.deal_web_view_holder); // Hide the Scollbar sView.setVerticalScrollBarEnabled(false); sView.setHorizontalScrollBarEnabled(false); 

http://developer.android.com/reference/android/view/View.html#setVerticalScrollBarEnabled%28boolean%29

like image 25
jkhouw1 Avatar answered Oct 17 '22 04:10

jkhouw1