Search code examples
androidandroid-edittextfill-parent

Why EditText is not expanding to fill_parent


I have written an XML code, where I want the EditText to be expanded to fit the parent width. After spending so much time, I can not find a way to expand the EditText.

Here is my XML:

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout 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:orientation="vertical">

    <TableRow 
        android:layout_marginLeft="10dp" 
        android:layout_marginBottom="15dip">        
        <TextView
            android:text="Comment"
            android:layout_width="match_parent"
            android:textStyle="bold"
            android:padding="3dip" />      
    </TableRow>

    <TableRow 
        android:layout_marginLeft="10dp" 
        android:layout_marginBottom="15dip">        
       <EditText 
            android:id="@+id/EditText02"
            android:layout_height="wrap_content"
            android:lines="5" 
            android:gravity="top|left" 
            android:inputType="textMultiLine"
            android:scrollHorizontally="false" 
            android:minWidth="10.0dip"
            android:maxWidth="5.0dip"/>
    </TableRow>

    <TableRow 
        android:layout_marginLeft="10dp" 
        android:layout_marginBottom="15dip"
        android:gravity="center">           
       <Button 
            android:id="@+id/cancel"
            android:text="Next" />       
   </TableRow>
</TableLayout>
</LinearLayout>

what i have made wrong here. Please help me.


Solution

  • Add an extra colomn of TextView in every row.

    This code may help you.

    <?xml version="1.0" encoding="UTF-8"?>
    
    <LinearLayout 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:stretchColumns="1"
        android:orientation="vertical">
    
        <TableRow 
            android:layout_width="fill_parent"
            android:layout_marginLeft="10dp" 
            android:layout_marginBottom="15dip"> 
    
            <TextView android:text="" />    
    
            <TextView
                android:text="Comment"
                android:layout_width="match_parent"
                android:layout_marginRight="10dp"
                android:textStyle="bold"
                android:padding="3dip" />      
        </TableRow>
    
        <TableRow 
            android:layout_marginLeft="10dp" 
            android:layout_marginBottom="15dip"> 
    
            <TextView android:text="" />        
    
           <EditText 
                android:id="@+id/EditText02"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="20dp"
                android:lines="5" 
                android:gravity="top|left" 
                android:inputType="textMultiLine"
                android:scrollHorizontally="false" />
        </TableRow>
    
        <TableRow 
            android:layout_marginLeft="10dp" 
            android:layout_marginBottom="15dip"
            android:gravity="center">
    
            <TextView android:text="" />        
    
           <Button 
                android:id="@+id/cancel"
                android:layout_marginRight="10dp"
                android:text="Next" />       
       </TableRow>
    </TableLayout>
    </LinearLayout>