問題描述
我有一個聯系表單,我想在其中添加一些圖標到我的編輯文本中以獲得更好的外觀.我想創建如下所示的 EditText.
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.
我有如下所示的 EditText.我得到了類似的結果.我希望圖像絕對在左側,就像上圖一樣.我知道 EditText 內部使用的是九個補丁圖像,我認為這就是結果有些不同的原因.有誰知道如何解決這個問題?
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" />
推薦答案
不要使用 android:drawableLeft="@drawable/name_icon_edittext"
,而是為name_icon
.這樣,您可以更好地控制將其放置在 layout
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
注意:我假設你的 layout
是 RelativeLayout
這篇關于在 Android 中的 EditText 左側設置圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!