-3 java android android-layout
我想将 imageview 放在 edittext 中。可能吗?我检查了“evernote”应用程序,它能够将照片放在编辑文本部分。我想让我的应用程序完全一样。我如何能够放置从图库中选择的图像视图,并将照片放置在编辑文本中?
我首先尝试将 imageview 放在 .xml 文件中的 relativelayout 中,但它给我一个错误标志。
我应该在 .xml 文件上做吗?或者我应该制作自己的edittext java文件才能做到这一点?
用这个:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edit_text"
android:drawablePadding="8dp"
android:drawableRight="@drawable/yourImage"/>
Run Code Online (Sandbox Code Playgroud)
您可以根据需要使用可绘制的文本左侧、右侧、顶部或底部。
要在 Java 中进行操作,请使用以下命令:
EditText editText = (EditText) findViewById(R.id.yourEditTextId);
editText.setCompoundDrawablesWithIntrinsicBounds(left,top,right,bottom);
Run Code Online (Sandbox Code Playgroud)
用于操作右侧设置的图像:
editText.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.yournewimage,0);
Run Code Online (Sandbox Code Playgroud)
同样,您可以为其他情况执行此操作。
希望能帮助到你!!!