从Android中的ScrollView中删除滚动条轨道
我的 Android 应用程序有一个主 WebView(从本地资源加载的 HTML),我想使用屏幕的整个宽度并能够(垂直)滚动。因此,我将 WebView 包装在布局 XML 中的 ScrollView 中,但无论我做什么,我似乎都无法从滚动视图的右侧删除滚动条轨道。更糟糕的是,我似乎无法更改滚动条轨道的背景颜色。
该轨道占用大约 10dp 左右,这给 WebView 中的 HTML 带来了问题。我希望滚动条出现在网页视图的顶部(iPhone 风格,如果你明白我的意思的话)。现在,您可能会说“为什么不将 HTML 改薄 10px?”,这是我的后备解决方案,但我宁愿不必这样做。
这是布局 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>
我的目标是平台 2.1 / API lvl 7,实际上只是处理正常尺寸的显示、mdp、hdp 和 xhdp。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要通过 xml 从视图(及其子类)中删除滚动条:
http://developer.android.com/reference/android/view/View.html#attr_android:滚动条
To remove a scrollbar from a view (and its subclass) via xml:
http://developer.android.com/reference/android/view/View.html#attr_android:scrollbars
尝试这是您的 onCreate 活动:
http://developer. android.com/reference/android/view/View.html#setVerticalScrollBarEnabled%28boolean%29
try this is your activity onCreate:
http://developer.android.com/reference/android/view/View.html#setVerticalScrollBarEnabled%28boolean%29
我有点困惑为什么你首先要将
WebView
放入ScrollView
中。WebView
有它自己的内置滚动系统。关于您的实际问题,如果您希望
Scrollbar
显示在顶部,您可以使用I'm a little confused why you are putting a
WebView
into aScrollView
in the first place. AWebView
has it's own built-in scrolling system.Regarding your actual question, if you want the
Scrollbar
to show up on top, you can use通过将其添加到我的
ListView
中解决了我的问题:Solved my problem by adding this to my
ListView
:在我的情况下,这些解决方案在“相对布局”和“如果键盘打开”的情况下失败
android:scrollbars="none"
&android:scrollbarStyle="insideOverlay"
也不起作用。工具栏不见了,我的完成按钮也不见了。
这个为我工作
These solutions Failed in my case with Relative Layout and If KeyBoard is Open
android:scrollbars="none"
&android:scrollbarStyle="insideOverlay"
also not working.toolbar is gone, my done button is gone.
This one is Working for me
通过使用下面的方法,解决了问题
By using below, solved the problem