2011-02-04 97 views
6

我尝试创建一个从应用程序,在应用程序中我有一个冗长的形式,我想在滚动视图,但是当我添加EditText到scrollView ..日食显示一些错误在其设计师看来。在滚动视图中的EditText在android

error! 
IllegalStateException: ScrollView can host only one direct child 
Exception details are logged in Window > Show View > Error Log 

任何人都有想破解它的想法吗?


我在为上述问题得到解决方案后包含了这段代码。

现在EditText没有显示任何输入的文本,它只是给出了一些建议...!

我有下面的XML:

<ScrollView 
android:id="@+id/widget64" 
android:layout_width="320px" 
android:layout_height="358px" 
android:fillViewport="true" 
android:isScrollContainer="true" 
android:saveEnabled="true"> 
<TableLayout 
android:id="@+id/widget58" 
android:layout_width="320px" 
android:layout_height="65px" 
android:orientation="vertical" 
> 
<TableRow 
android:id="@+id/widget60" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 
<TextView 
android:id="@+id/user" 
android:text="User" 
android:textColor="#000000"> 
</TextView> 
</TableRow> 
<TableRow 
android:id="@+id/widget60" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:gravity="center" 
> 
<EditText 
android:id="@+id/users_first_name" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:hint="First Name" 
android:focusable="true" 
android:inputType="textPersonName" 
android:enabled="true" 
android:ems="15"> 
</EditText> 
</TableRow> 
</TableLayout> 
</ScrollView> 

发现麻烦..... 我的模拟器键设置为中国,而不是英语......

回答

7

首先添加任何布局然后将edittext添加到该布局。然后自动获得该编辑文本的滚动。对于Ex:将Linearlayout添加到该滚动视图,然后将editText添加到linearlayout。

+0

谢谢lot..it工作 – rahul 2011-02-04 06:42:47

+0

我怎么可以给它..? – rahul 2011-02-04 07:18:14

5

是的,ScrollVew只能有一个孩子。 对于这个做这样的事情

<ScrollView 
    fillViewPortView = "true"> 

    <RelativeLayout> 
      // Design the entire layout in here 
      // Put your elements one below the other. It will automatically scroll 
      // dont forget to setFillViewPort view to true in ScrollView 
    </RelativeLayout> 
</ScrollView> 

这将解决这个问题肯定
希望他的帮助:)