在edittext android中插入imageview [英] Inserting imageview inside edittext android

查看:253
本文介绍了在edittext android中插入imageview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将imageview放置在edittext内.可能吗?我检查了"evernote"应用程序,它能够将照片放在edittext部分上. 我想使我的应用程序完全一样.我如何将从图库中选择的imageview放置到edittext中?

I want to place imageview inside edittext. Would it be possible? I checked "evernote" application, and it was able to put photo on the edittext part. I want to make my application exactly as same. How would I be able to put imageview that was chosen from the gallery, and place the photo inside edittext?

我首先尝试将imageview放在.xml文件的relativelayout内,但是这给我带来了一个错误标志.

I first tried to put imageview inside relativelayout in .xml file, but it threw me a error sign.

我应该在.xml文件上做什么吗? 还是我应该制作自己的edittext java文件?

Should I do on .xml file? Or should I make my own edittext java file in order to do that?

推荐答案

使用此:

<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/edit_text"
        android:drawablePadding="8dp"
        android:drawableRight="@drawable/yourImage"/>

您可以根据需要使用可绘制的文本的左,右,顶部或底部.

you can use drawable left,right,top or bottom of your text according to your need.

要在Java中进行操作,请使用以下代码:

To manipulate in java use this:

EditText editText = (EditText) findViewById(R.id.yourEditTextId);
editText.setCompoundDrawablesWithIntrinsicBounds(left,top,right,bottom);

用于操作设置在右侧的图像:

for manipulating image set on right:

editText.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.yournewimage,0);

对于其他情况,您也可以这样做.

similarly you can do it for other cases.

希望有帮助!

这篇关于在edittext android中插入imageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆