如何使我的布局水平和垂直滚动?
我正在使用表格布局。我需要对此布局进行水平和垂直滚动。默认情况下,我可以在视图中进行垂直滚动,但水平滚动不起作用。
我正在使用 Android SDK 1.5 r3。我已经尝试过android:scrollbars="horizontal"
。
我在一些论坛上读到,在纸杯蛋糕更新中,水平滚动是可能的。
如何使我的布局双向滚动?
I am using a TableLayout. I need to have both horizontal and vertical scrolling for this layout. By default I am able to get vertical scrolling in the view but horizontal scrolling is not working.
I am using Android SDK 1.5 r3. I have already tried android:scrollbars="horizontal"
.
I have read on some forums that in the cupcake update, horizontal scrolling is possible.
How can I make my layout scroll in both directions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我找到了一种简单的方法来实现这两种滚动行为。
这是它的 xml:
I was able to find a simple way to achieve both scrolling behaviors.
Here is the xml for it:
为时已晚,但我希望您的问题能通过此代码快速解决。
没什么可做的,只需将您的代码放在滚动视图下面即可。
its too late but i hope your issue will be solve quickly with this code.
nothing to do more just put your code in below scrollview.
在这篇文章中在android中滚动视图垂直和水平他们讨论了一个可能的解决方案,引用:
Matt Clark 基于 Android 源代码构建了一个自定义视图,并且它似乎工作得很好: http://blog.gorges.us/2010/06/android-two-Dimension-scrollview
请注意,该页面中的类在计算视图的水平宽度时存在错误。 Manuel Hilty 的修复位于注释中:
解决方案:将第 808 行的语句替换为以下内容:
In this post Scrollview vertical and horizontal in android they talk about a possible solution, quoting:
Matt Clark has built a custom view based on the Android source, and it seems to work perfectly: http://blog.gorges.us/2010/06/android-two-dimensional-scrollview
Beware that the class in that page has a bug calculating the view's horizonal width. A fix by Manuel Hilty is in the comments:
Solution: Replace the statement on line 808 by the following:
由于其他解决方案很旧,要么工作不佳,要么根本无法工作,我修改了
NestedScrollView
,它稳定、现代,并且具有您对滚动视图的所有期望。除了水平滚动。这是仓库: https://github.com/ultimate-deej/TwoWayNestedScrollView
我已经除了绝对必要的内容之外,没有对原始
NestedScrollView
进行任何更改或“改进”。该代码基于
androidx.core:core:1.3.0
,这是撰写本文时的最新稳定版本。以下所有功能均有效:
NestedScrollView
)Since other solutions are old and either poorly-working or not working at all, I've modified
NestedScrollView
, which is stable, modern and it has all you expect from a scroll view. Except for horizontal scrolling.Here's the repo: https://github.com/ultimate-deej/TwoWayNestedScrollView
I've made no changes, no "improvements" to the original
NestedScrollView
except for what was absolutely necessary.The code is based on
androidx.core:core:1.3.0
, which is the latest stable version at the time of writing.All of the following works:
NestedScrollView
)使用这个:
示例:
Use this:
Example:
您可以使用下面的代码来做到这一点
You can do this by using below code
此实现始终可以显示水平和垂直滚动条
Activity_main.xml
MainActivity.java
This implementation can always display both horizontal and vertical scrollbars
activity_main.xml
MainActivity.java
遇到了同样的问题(SDK 34),但是对于 AppBarLayout,我没有找到有效的解决方案。最后,这个解决方案适用于我的大型 Tablelayout 和 AppBarLayout:
Had the same problem (SDK 34), but with AppBarLayout no solution i found works. Finally, this solution works with my large Tablelayout and AppBarLayout: