Android - HorizontalScrollView 不能包含任何内容
我正在使用自定义布局来修改 HorizontalScrollView 的功能以满足我的目的,但即使在最低限度的测试应用程序中,我也无法使该视图正常工作。
我已经完成了一些关于制作自定义布局的小教程,似乎我可以将其添加进去,但是当我尝试添加任何内容作为该视图的子视图时,我收到错误“IllegalStateException:HorizontalScrollView 只能托管一个直系子女”。无论子级是另一个布局,还是只是一个按钮,它都会执行此操作。
我确信这有一个简单的原因,只是我找不到它。如果您知道问题可能是什么,您将成为我的英雄,为我指明正确的方向。先感谢您!
I'm working with a custom layout to modify the functionality of HorizontalScrollView for my purposes, but I'm having problems getting that view working, even in a bare minimum test app.
I've went through a little tutorial on making custom layouts, and it seems like I can get it added in, but when I try to add anything as a child of that view I'm given the error "IllegalStateException: HorizontalScrollView can host only one direct child". It does this regardless if the child is another layout, or even just a single button.
I'm sure there's a simple reason for this, I just can't find it. If you have any idea what the issue might be you would be my hero to point me in the right direction. Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能有点晚了,但我想我知道你做错了什么。
HorizontalScrollView 只能承载一个直接子级。这意味着,您不能在该 ScrollView 中定义多个子级。因此,只需添加一个 LinearLayout 或类似的东西,然后将您的按钮或任何您需要的东西添加到该 LinearLayout 中。 :)
当然,当您在 java 类中扩展 HorizontalScrollView 时,您也可以执行相同的操作。只需添加一个 Layout 并将要添加到 ScrollView 的内容放入该 Layout 中即可。
Might be a bit late but I think I know what you're doing wrong.
HorizontalScrollView can host only one direct child. That means, you must not define more than one child into this ScrollView. So just add a LinearLayout or something like that and then add your Buttons or whatever you need into that LinearLayout. :)
Of course you can do the same when you extend HorizontalScrollView in your java class. Just add one Layout and put in that Layout the things you want to add to the ScrollView.