开发者

Android - Problem of WrapText in Edittext

I am facing trouble to set WrapText kind of facility in EditText.

Problem: When i try tp enter data in EditText, it goes beyond the screen width (scrolling horizontally). Instead of it should be appear in next-line.

Want to perform:开发者_JS百科 Actually, i want to implement multiline edittext, initially it should display with single-line as usual, but it will be expanded vertically(not horizontally) as when data is being entered.

Please suggest me what should i do ??

Please have a look at below image:

Android - Problem of WrapText in Edittext

I have done the below XML coding:

<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>


You can try to change the width to fill_parent.


try adding following code in your edit text if you want to wrap it in a single line:

android:singleLine="true"

OR set the width of your edittext to fill_parent or any value in dip if you want multiline.


I just change this: android:layout_width ="0dip" and it is working fine.

Multiline edittext but initially it is being displayed one line, it will be expanded vertically(not horizontally) as and when the more and more data are being entered.


Just use both android:stretchColumns="1" and android:shrinkColumns="1" instead the only one 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">


I've tested it on a 2.1 emulator enclosing the code (with fill_parent in the edit text) inside this relative layout and appears to be ok.

<?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>

Maybe you can navigate the xml tree in the eclipse outline window and see what view is bigger than the screen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜