简体   繁体   中英

How to change image size in EditText?

I set the picture to my EditText using android:drawableLeft But I had a problem in the size of this picture, how can I change it in xml?

xml

    <EditText
        android:id="@+id/RegisterActivity_EditText_Email"
        android:layout_width="288dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="27dp"
        android:background="@drawable/field_edit_text_style"
        android:fontFamily="sans-serif-light"
        android:drawableLeft="@drawable/mail_img_foreground"
        android:inputType="textEmailAddress"
        android:gravity="center"

you can set the layout_height like this

<EditText
    android:id="@+id/RegisterActivity_EditText_Email"
    android:layout_width="288dp"
    android:layout_height="50dp"
    android:layout_marginTop="27dp"
    android:background="@drawable/field_edit_text_style"
    android:fontFamily="sans-serif-light"
    android:drawableLeft="@drawable/mail_img_foreground"
    android:inputType="textEmailAddress"
    android:gravity="center"

You can always cheat and use:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/field_edit_text_style">

<EditText
        android:id="@+id/RegisterActivity_EditText_Email"
        android:layout_width="288dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="27dp"
        android:layout_marginLeft="-10dp"
        android:layout_toRightOf="@+id/icon"
        android:background=""
        android:fontFamily="sans-serif-light"
        android:padding="10dp"
        android:inputType="textEmailAddress"
        android:gravity="center"/>

    <ImageView
        android:padding="3dp"
        android:id="@+id/icon"
        android:src="@drawable/perm_group_personal_info"
        android:layout_width="40dp"
        android:layout_height="40dp" />

</RelativeLayout>

You just need a Linear Layout.

Add ImageView and EditText in LinearLayout and set 'layout Orientation' horizontal.

android:orientation="horizontal"

Try below code after changing height and width accordingly.

<LinearLayout
    android:layout_width="width"
    android:layout_height="height"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="width"
        android:layout_height="height"
        android:src="@drawable/mail_img_foreground" />

    <EditText
        android:id="@+id/RegisterActivity_EditText_Email"
        android:layout_width="288dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="27dp"
        android:background="@drawable/field_edit_text_style"
        android:fontFamily="sans-serif-light"
        android:gravity="center"
        android:inputType="textEmailAddress" />

</LinearLayout>

Feel free to ask in comments. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM