2014-09-22 59 views
0

我是android编程的新手,我有一个问题“一个scrollview只能有一个孩子”我的脚本有什么问题? 我想知道你是否需要服用ScroolView?或者我该如何解决这个问题?任何人都可以正确编辑scrpt?scrollview只能有一个孩子

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="-1" 
android:layout_height="-1"> 
<LinearLayout 
android:orientation="1" 
android:layout_width="-1" 
android:layout_height="-1"> 

<LinearLayout 
android:orientation="1" 
android:layout_width="-1" 
android:layout_height="-1" 
android:layout_marginLeft="12800" 
android:layout_marginTop="2560"> 

<TextView 
android:textColor="-1" 
android:layout_width="-2" 
android:layout_height="-2" 
android:text="2131034150"/> 

<Spinner 
android:id="2131165208" 
android:layout_width="94720" 
android:layout_height="-2" 
android:drawSelectorOnTop="-1" 
android:prompt="2131034149"/> 



<TextView 
android:textColor="-1" 
android:layout_width="-2" 
android:layout_height="-2" 
android:text="2131034143"/> 
<EditText 
android:id="2131165202" 
android:layout_width="-2" 
android:layout_height="-2" 
android:maxLines="1" 
android:width="94721" 
android:maxLength="50"/> 
<TextView 
android:textColor="-1" 
android:layout_width="-2" 
android:layout_height="-2" 
android:text="2131034144"/> 
<EditText 
android:id="2131165203" 
android:layout_width="-2" 
android:layout_height="-2" 
android:maxLines="1" 
android:width="94721" 
android:password="-1" 
android:maxLength="30"/> 
</LinearLayout> 
<LinearLayout 
android:layout_gravity="3" 
android:orientation="0" 
android:paddingLeft="58881" 
android:paddingBottom="5121" 
android:layout_width="-2" 
android:layout_height="-2"> 
<Button 
android:id="2131165204" 
android:layout_width="-2" 
android:layout_height="-2" 
android:text="2131034145" 
android:width="35841"/> 
</LinearLayout> 
</LinearLayout> 
</ScrollView> 

回答

3

错误是不言自明的。

一个滚动视图只能有一个直接的孩子。

所以做一个容器布局,其中包含所有的孩子。并将该容器布局放置在滚动视图中。

示例层次:

<ScrollView> 
    <LinearLayout> <!-- new container layout--> 

     <!-- all your children layouts, views --> 
    </LinearLayou> 
</ScrollView> 
0

是它,当你在设计一个布局,你只能有了滚动的一个孩子是在Android应用程序如此。而解决这个问题你必须做一个为孩子和所有其他的意见和部件将里面的类似下面的代码

<ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

     <!-- all other childs (more than one) can be placed here --> 

     </Linearlayout> 
    </ScrollView> 
1

首先-1 -2等都是无效的值视图和布局的高度和宽度。

问题是自我描述;一个ScrollView里面不能有超过1 View

把根内的所有的意见LinearLayout

+0

我意识到这是一个老帖子,但你可以详细阐述**的无效 - 1 -2 **?我已经继承了一些具有类似宽度和高度值的代码,AndroidStudio正在抛出错误。任何想法为什么这存在,以及如何处理它? – 2016-06-24 13:30:04

+0

这非常明显。任何视图的高度/宽度可以是0或更大。负高度/宽度是不合逻辑的。视图边距和填充可以是-ve但不是大小。 – SMR 2016-06-27 05:39:19

0

滚动视图不是布局。它只是一个容器,您可以在其中定义布局。 所以你必须在scrollView中定义你的布局;然后将所需的任何东西添加到布局。 这样的意见是滚动的孙子

你的代码应该是这样的

相关问题