Android - Horizo​​ntalScrollView 不能包含任何内容

发布于 2024-10-09 04:17:22 字数 310 浏览 0 评论 0原文

我正在使用自定义布局来修改 Horizo​​ntalScrollView 的功能以满足我的目的,但即使在最低限度的测试应用程序中,我也无法使该视图正常工作。

我已经完成了一些关于制作自定义布局的小教程,似乎我可以将其添加进去,但是当我尝试添加任何内容作为该视图的子视图时,我收到错误“IllegalStateException:Horizo​​ntalScrollView 只能托管一个直系子女”。无论子级是另一个布局,还是只是一个按钮,它都会执行此操作。

我确信这有一个简单的原因,只是我找不到它。如果您知道问题可能是什么,您将成为我的英雄,为我指明正确的方向。先感谢您!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗琴音 2024-10-16 04:17:22

可能有点晚了,但我想我知道你做错了什么。
Horizo​​ntalScrollView 只能承载一个直接子级。这意味着,您不能在该 ScrollView 中定义多个子级。因此,只需添加一个 LinearLayout 或类似的东西,然后将您的按钮或任何您需要的东西添加到该 LinearLayout 中。 :)

<HorizontalScrollView ...>
  <LinearLayout ...>
    <LinearLayout ... />
    <Button ... />
    </TextView ... />
    < ... />
  </LinearLayout>
</HorizontalScrollView>

当然,当您在 java 类中扩展 Horizo​​ntalScrollView 时,您也可以执行相同的操作。只需添加一个 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. :)

<HorizontalScrollView ...>
  <LinearLayout ...>
    <LinearLayout ... />
    <Button ... />
    </TextView ... />
    < ... />
  </LinearLayout>
</HorizontalScrollView>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文