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.
我的Android应用程序有一个主要的WebView(从本地资源加载的HTML),我想使用整个屏幕的宽度,并且能够(垂直地)滚动。所以我在我的布局XML中将WebView包装在一个ScrollView中,但是无论我做什么,我似乎都无法从滚动视图的右侧删除滚动条跟踪。更糟糕的是,我似乎无法改变滚动条轨迹的背景颜色。
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.
这个跟踪大约占用了10dp,这在WebView中为HTML创建了问题。我希望滚动条出现在web视图的顶部(iPhone风格,如果你知道我的意思的话)。现在,你可以说“为什么你不把你的HTML改成10px薄呢?”,这是我的备用方案,但我不需要这么做。
Here's the relevant snippet of layout XML, you'll see I've tried every android:etc attribute I could find:
这是布局XML的相关代码片段,你会看到我已经尝试了所有我能找到的android:etc属性:
<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.
我的目标是平台2.1 / API lvl 7,实际上只是处理正常大小的显示器,mdp, hdp和xhdp。
5 个解决方案
#1
456
To remove a scrollbar from a view (and its subclass) via xml:
通过xml从视图(及其子类)中删除滚动条:
android:scrollbars="none"
http://developer.android.com/reference/android/view/View.html#attr_android:scrollbars
http://developer.android.com/reference/android/view/View.html attr_android:滚动条
#2
26
try this is your activity onCreate:
试试这是你的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 % 28布尔% 29
#3
17
I'm a little confused why you are putting a WebView
into a ScrollView
in the first place. A WebView
has it's own built-in scrolling system.
我有点搞不懂你为什么要把WebView放到ScrollView中。WebView有自己的内置滚动系统。
Regarding your actual question, if you want the Scrollbar
to show up on top, you can use
关于您的实际问题,如果您希望滚动条显示在顶部,您可以使用
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY) or
android:scrollbarStyle="insideOverlay"
#4
3
Solved my problem with adding this to my Listview
把它添加到Listview解决了我的问题
android:scrollbars="none"
#5
3
These solutions Failed in my case with Relative Layout and If KeyBoard is Open android:scrollbars="none"
& android:scrollbarStyle="insideOverlay"
also not working.
这些解决方案在我的相对布局和If键盘是打开的情况下失败了:scrollbars="none" & android:scrollbarStyle="insideOverlay"也不工作。
toolbar is gone, my done button is gone.
工具栏没了,我的完成按钮没了。
This one is Working for me
这个对我有用
myScrollView.setVerticalScrollBarEnabled(false);
#1
456
To remove a scrollbar from a view (and its subclass) via xml:
通过xml从视图(及其子类)中删除滚动条:
android:scrollbars="none"
http://developer.android.com/reference/android/view/View.html#attr_android:scrollbars
http://developer.android.com/reference/android/view/View.html attr_android:滚动条
#2
26
try this is your activity onCreate:
试试这是你的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 % 28布尔% 29
#3
17
I'm a little confused why you are putting a WebView
into a ScrollView
in the first place. A WebView
has it's own built-in scrolling system.
我有点搞不懂你为什么要把WebView放到ScrollView中。WebView有自己的内置滚动系统。
Regarding your actual question, if you want the Scrollbar
to show up on top, you can use
关于您的实际问题,如果您希望滚动条显示在顶部,您可以使用
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY) or
android:scrollbarStyle="insideOverlay"
#4
3
Solved my problem with adding this to my Listview
把它添加到Listview解决了我的问题
android:scrollbars="none"
#5
3
These solutions Failed in my case with Relative Layout and If KeyBoard is Open android:scrollbars="none"
& android:scrollbarStyle="insideOverlay"
also not working.
这些解决方案在我的相对布局和If键盘是打开的情况下失败了:scrollbars="none" & android:scrollbarStyle="insideOverlay"也不工作。
toolbar is gone, my done button is gone.
工具栏没了,我的完成按钮没了。
This one is Working for me
这个对我有用
myScrollView.setVerticalScrollBarEnabled(false);