2014-09-22 55 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中定義你的佈局;然後將所需的任何東西添加到佈局。 這樣的意見是滾動的孫子

你的代碼應該是這樣的

相關問題