2011-01-12 82 views
2

我在EditText中设置WrapText类型的工具时遇到了麻烦。Android - 编辑文本中WrapText的问题

问题:当我尝试tp在EditText中输入数据时,它超出了屏幕宽度(水平滚动)。而不是它应该出现在下一行。

要执行:事实上,我想要实现多行的EditText,最初它应与单行照常显示,但将垂直扩展(未水平地)被输入的数据时相同。

请问我该怎么办?

请各位看看下面的图像:

alt text

我也做了以下XML编码:

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingTop="10dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:stretchColumns="1"> 

    <TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent" android:layout_height="wrap_content"> 
     <TextView 
      android:text="Name:" 
      android:id="@+id/TextView01" 
      android:layout_width="80dp" 
      android:layout_height="wrap_content" 
      android:textSize="16dip"> 
     </TextView> 
     <EditText 
      android:id="@+id/txtViewName" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:inputType="textFilter|textMultiLine|textNoSuggestions" 
      android:scrollHorizontally="false"> 
     </EditText> 
    </TableRow> 
</TableLayout> 
+0

请查看以上的更新:要执行: – 2011-01-12 09:10:53

+0

@ PM-帕雷什-mayani为什么RelativeLayout的不使用,我想它会工作精细。 – 2011-01-12 09:25:49

回答

1

我只是改变这一点:android:layout_width ="0dip"它工作正常。

多行edittext,但最初它被显示一行,当输入越来越多的数据时,它将被垂直扩展(不水平)。

2

你可以尝试改变宽度FILL_PARENT。

+0

不工作,我试过了,没有成功,输入更多文本时,edittext水平滚动。 – 2011-01-12 09:04:27

1

尝试在编辑文本中添加以下代码,如果你想将其包装在一个单行:

android:singleLine="true"

或者如果你想多设置您的EditText在浸宽度FILL_PARENT或任何价值。

+0

没有成功,我已经尝试了你所说的方式。 – 2011-01-12 09:07:51

+0

嘿检查这个android:inputType =“textFilter | textMultiLine”在我的问题,然后howz有可能设置android:singleLine =“true”,它是否有任何意义? – 2011-01-12 09:13:21

-2

我已经测试了这个相对布局内的2.1模拟器封闭的代码(在编辑文本FILL_PARENT)和似乎是好的。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingTop="10dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:stretchColumns="1"> 

    <TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent" android:layout_height="wrap_content"> 
     <TextView 
      android:text="Name:" 
      android:id="@+id/TextView01" 
      android:layout_width="80dp" 
      android:layout_height="wrap_content" 
      android:textSize="16dip"> 
     </TextView> 
     <EditText 
      android:id="@+id/txtViewName" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:inputType="textFilter" 
      android:scrollHorizontally="false"> 
     </EditText> 
    </TableRow> 
</TableLayout> 
</RelativeLayout> 

也许你可以浏览在Eclipse大纲窗口XML树,看看有什么看法比屏幕大。

1

只需使用两android:stretchColumns="1"android:shrinkColumns="1",而不是只有一个android:stretchColumns="1"

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingTop="10dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:stretchColumns="1" 
    android:shrinkColumns="1">