Monty Sharma
Monty Sharma

Reputation: 177

How to increase width of particular EditText in Table Raw (Table layout)

I am using Table Layout.

Here i have three EditText's with same width ="200dp".

But i want to increase the size of 3rd EditText.

I made its width="wrap_content" but all other EditText also getting "wrap_content"

How can i increase the width of 3rd EditText with out affecting other EditText's.

This code for 3rd EditText:-

 <TableRow 
            android:gravity="center_horizontal" 
            android:layout_marginBottom="10dp">
            <TextView 
                android:layout_width="match_parent" 
                android:layout_height="wrap_content" 
                android:gravity="left" 
                android:id="@+id/addl" 
                android:text="Address" 
                />
            <TextView 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:gravity="right" 
                android:id="@+id/colon"
                            android:text=":" />

            <EditText 
                android:layout_width="250dp" 
                android:layout_marginLeft="20dp" 
                android:id="@+id/et"
                android:singleLine="true"/>            
        </TableRow>

enter image description here Now i want to increase width of Address EditText only

Upvotes: 1

Views: 2897

Answers (2)

sunil
sunil

Reputation: 6614

i think you can achieve this by layout_weight parameter of EditTexts like below

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout12"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#909090"
    android:padding="10dp" >

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Student ID"
            android:textColor="#000000" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text=":"
            android:textColor="#000000" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="6" />
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name"
            android:textColor="#000000" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text=":"
            android:textColor="#000000" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Class"
            android:textColor="#000000" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text=":"
            android:textColor="#000000" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Address"
            android:textColor="#000000" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text=":"
            android:textColor="#000000" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </TableRow>

</TableLayout>

EDIT

This is the outcome

enter image description here

Upvotes: 4

PC.
PC.

Reputation: 7024

put the property android:stretchColumns="2" in TableLayout

<TableLayout android:stretchColumns="2" ... > .... </TableLayout>

Upvotes: 0

Related Questions