上的EditText在Android的左侧设置图片图片、EditText、Android

2023-09-05 10:05:50 作者:总有智障想害朕

我有一个接触形式,我想一些图标添加到我的编辑文本更好看。我想创造的EditText像下面。

我的EditText如下图所示。而我得到的结果类似。我想要的图像,以绝对的左侧,因为它是在上述的图像。我知道,在内部的EditText是使用九修补形象,我认为这就是为什么结果是一些什么样的不同。任何人都可以知道如何解决?

 <的EditText
            机器人:ID =@ + ID /名称
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =51dip
            机器人:提示=@字符串/名称
            机器人:inputType =文本
            机器人:drawableLeft =@可绘制/ name_icon_edittext/>
 

解决方案

而不是使用的android:drawableLeft =@可绘制/ name_icon_edittext,创建单独的 ImageView的 name_icon 。 这样你有更多的控制上放置的布局

注意:我假设你的布局 RelativeLayout的

DropEditText首页 文档和下载 Android 下拉列表 OSCHINA

I am having one contact form in which I would like to add some icons to my edit text for a better look. I want to create EditText something like below.

I have EditText like below. And I got the result something like. I want the image to be absolutely on the left side as it is in the above image. I know that internally EditText is using Nine Patch image and i think that is why the result is some what different. Can anyone know how to resolve this?

<EditText
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="51dip"
            android:hint="@string/name"
            android:inputType="text"
            android:drawableLeft="@drawable/name_icon_edittext" />

解决方案

Instead of using android:drawableLeft="@drawable/name_icon_edittext", create separateImageView for the name_icon. This way you have more control on placing it on the layout

Note: I am assuming your layout is RelativeLayout