2013-01-14 47 views
-1

我试图滚动视图布局添加到此布局:如何将ScrollView添加到布局?

a busy cat

我得到这个错误。

ScrollView can host only one direct child 

我该如何解决这个问题?

+0

您可以将一个垂直“LinearLayout”放入ScrollView中并添加其他视图/布局。 – harism

+0

我已经尝试过,但我会再试一次。谢谢。 – mertaydin

回答

3

滚动型不能包含一个以上的孩子在他的体内

WRONG

<ScrollView> 
    <LinearLayout> 
     xxxxx 
    </LinearLayout> 
    <LinearLayout> 
     xxxxx 
    </LinearLayout> 
<ScrollView> 

RIGHT

<ScrollView> 
    <LinearLayout> 
    <LinearLayout> 
     xxxxx 
    </LinearLayout> 
    <LinearLayout> 
     xxxxx 
    </LinearLayout> 
    </LinearLayout> 
<ScrollView> 

只有一个直接子。

+0

当我将Linearlayout添加为仅有的一个直接子对象时,在这种情况下,所有设计都打破了。 – mertaydin

+0

好的谢谢。我解决了我的问题。这个问题完全是关于我的错误。再次感谢。 – mertaydin

2

您只能在ScrollView中添加一个View。所以添加一个LinearLayout在ScrollView中说L1并在该LinearLayout(L1)中添加所有其他视图。