4

I have a linearlayout in which i have one image view, one textview, two edittext and button.

When i run my application in emulator or in my device the height of the edittexts seems bigger in size rather they should be single line edittext boxes.

My layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@android:color/white">
    <TextView android:id="@+id/item_blank" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:padding="2dp" 
        android:textSize="14dp" 
        android:textColor="@android:color/black"
        android:background="@android:color/white" 
        android:text=" "/>
    <ImageView android:id="@+id/test_image" 
        android:src="@drawable/logo_infraline_energy"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center"/>
    <TextView android:id="@+id/item_title" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:padding="2dp" 
        android:textSize="14dp" 
        android:textColor="@android:color/black"
        android:background="@android:color/white" 
        android:text="Please put in your valid credentials to get access."/>
    <EditText android:id="@+id/userName" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:inputType="textEmailAddress" 
        android:layout_weight="1" 
        android:height="30dp"
        android:hint="Email Address" />
    <EditText android:id="@+id/password" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:hint="Password"
        android:height="30dp" 
        android:password="true" />
    <Button android:id="@+id/loginButton" 
        android:text="Login"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:onClick="login" />
</LinearLayout>
Hussain
  • 5,552
  • 4
  • 40
  • 50
Rahul Sharma
  • 3,637
  • 2
  • 20
  • 18

4 Answers4

10

Remove the Line:

android:layout_weight="1"

from both EditTexts and your EditTexts will be single lined. Cheers.

Khawar
  • 5,197
  • 4
  • 28
  • 52
4

That's because you gave your EditText a weight of 1. This tells the parent LinearLayout to grow the EditText to fill whatever empty space is left. Just remove weight=1 and you'll be fine :)

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
1

its the weight=1 as well as the height=30px. The layout_height=wrap_content is undermined by the weight=1 and the height=30px. get rid of both and youl have the desired layout

Adam Storm
  • 724
  • 1
  • 6
  • 13
1

just put android:layout_height="20px" instead of android:layout_height="wrap_content".

and remove android:layout_weight="1"

see if the editText will change in size.

Siten
  • 4,515
  • 9
  • 39
  • 64