ktk
ktk

Reputation: 21

Fix height of android EditText with a background

How can I get the button and the editText to have the same height? I want the EditText to have the height of the button View

<com.devmarvel.creditcardentry.library.CreditCardForm
    android:id="@+id/credit_card_form"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/dip_40"
    android:layout_marginLeft="@dimen/dip_20"
    android:layout_marginRight="@dimen/dip_20"
    app:text_color="@color/textColor"
    app:hint_text_color="@color/hintColor"
    app:cursor_color="@color/hintColor"
    app:include_helper="true"
    app:include_zip="false"
    app:input_background="@drawable/back_gray_border_round"
    app:include_exp="true"
    app:include_security="true"
    app:card_number_hint="@string/cardhint" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/dip_10"
    android:layout_marginRight="@dimen/dip_20"
    android:layout_marginLeft="@dimen/dip_20"
    android:text="@string/save"
    android:id="@+id/saveBtn"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/rounded_corner_button"
    android:textAllCaps="false"
    android:textSize="@dimen/normal_font_size"
    android:textColor="@color/white"
    android:textStyle="bold" />

I am using a library defined editText, but it does not have any height attribute.

Upvotes: 0

Views: 552

Answers (1)

bilal
bilal

Reputation: 2383

Add Both EditText and Button in RelativeLayout and use alginTop and alignBottom property on EditText.Have a look on code.I have hard code button size for illustration purpose.

<RelativeLayout 
 android:layout_width="match_parent"
 android:layout_height="match_parent">

<Button
    android:id="@+id/button"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:text="test"/>

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button"
    android:layout_alignTop="@+id/button"
    android:text="test2"/>

Upvotes: 1

Related Questions