Search code examples
androidxmllayoutandroid-edittexttext-size

EditText height changes according to the text size


If I change the textsize in editext, the height of edittext changes accordingly. I want the size of edittext to be same and I want a smaller sized hint or text to be in it. What should I do? Following is the code and I am also posting the screenshot of this layout :

  <RelativeLayout
            android:id="@+id/normal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#4594e4"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/set"
                android:layout_width="wrap_content"
                android:layout_height="75dp"
                android:layout_marginTop="05dp"
                android:padding="5dp"
                android:src="@drawable/bari" />

            <EditText
                android:id="@+id/etOrigin"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="@dimen/_35sdp"
                android:layout_marginTop="@dimen/_10sdp"
                android:layout_toEndOf="@+id/set"
                android:layout_toRightOf="@+id/set"
                android:background="#5fa7f1"
                android:inputType="textPersonName"
                android:text="My Location"
                android:textColor="#434343"
                android:textIsSelectable="true" />

            <EditText
                android:id="@+id/etDestination"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/etOrigin"
                android:layout_marginRight="@dimen/_35sdp"
                android:layout_marginTop="@dimen/_5sdp"
                android:layout_toEndOf="@+id/set"
                android:layout_toRightOf="@+id/set"
                android:background="#5fa7f1"
                android:inputType="textPersonName"
                android:onClick="wow"
                android:text="Where to go ?"
                android:textColor="#fff"
                android:textColorHint="#fff" />

            <ImageView
                android:id="@+id/swipe"
                android:layout_width="30dp"
                android:layout_height="27dp"
                android:layout_alignParentEnd="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="@dimen/_5sdp"
                android:background="@drawable/flip" />

        </RelativeLayout>

Screenshot of the layout before changing:

Screenshot of the layout before changing

Screenshot of layout after changing textsize:

Screenshot of layout after changing textsize


Solution

  • Use padding for this :-

             <EditText
                android:id="@+id/etOrigin"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="12dp"
                android:layout_marginRight="@dimen/_35sdp"
                android:layout_marginTop="@dimen/_10sdp"
                android:layout_toEndOf="@+id/set"
                android:layout_toRightOf="@+id/set"
                android:background="#5fa7f1"
                android:inputType="textPersonName"
                android:text="My Location"
                android:textColor="#434343"
                android:textIsSelectable="true" />