Jackie
Jackie

Reputation: 23577

Android TableLayout: Trying to make entried in 1 row larger than another

I have the following layout in my application

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
    <TextView 
        android:text="Username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:id="@+id/username"
        android:inputType="textEmailAddress"
        />
</TableRow>
<TableRow>
    <TextView 
        android:text="Password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:id="@+id/password"
        android:inputType="textPassword"
        />
</TableRow>
    <!-- ADDED NEW -->
<TableRow
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">
    <LinearLayout 
       android:layout_width="match_parent"
       android:layout_height="match_parent" >
        <CheckBox 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/savePwd"/>
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:text="Save Password (In encrypted clear text)"
            />

    </LinearLayout>
</TableRow>
<TableRow
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">
    <TextView 
        android:text="Please Log In"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/message_login"/>
</TableRow>
<TableRow android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="bottom|center">
    <Button 
    android:id="@+id/btn_login"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="Log In"/>
</TableRow>

</TableLayout>

The problem here is around the EditTexts. The TextViews expand to match the LinearLayout. This is not what I would like. I would like it to behave like the button below it (which doesn't expand the TextViews). Here is a screenshot...

Before...

Before

After

After

Upvotes: 1

Views: 301

Answers (3)

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp">
        <TextView
            android:text="Username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/username"
            android:layout_marginLeft="5dp"
            android:inputType="textEmailAddress"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp">
        <TextView
            android:text="Password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/password"
            android:layout_marginLeft="5dp"
            android:inputType="textPassword"/>
    </LinearLayout>
    <!-- ADDED NEW -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp">

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/savePwd"/>
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="5dp"
                android:text="Save Password (In encrypted clear text)"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp">
        <TextView
            android:text="Please Log In"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/message_login"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="bottom|center"
        android:layout_marginTop="5dp"
        android:layout_weight="1">
        <Button
            android:id="@+id/btn_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Log In"/>
    </LinearLayout>

</LinearLayout>

Upvotes: 0

Jackie
Jackie

Reputation: 23577

This Rows for the TextViews/EditText should look like this instead....

<TableRow>
    <TextView 
        android:text="Password"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.0" />
    <EditText 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2.0"
        android:id="@+id/password"
        android:inputType="textPassword"
        />
</TableRow>

Upvotes: 0

kerseyd27
kerseyd27

Reputation: 158

Since you are using weights on the Edit Texts, remove the android:layout_width="wrap_content" from the Edit Texts, and the weight will be extended how you like.

Upvotes: 2

Related Questions