开发者

Android - HorizontalScrollView cannot contain anything

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 g开发者_运维技巧iven 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜