Android的插入图像插入的EditText
问题描述:
我想加入一些图像分成的EditText下面代码:Android的插入图像插入的EditText
Bitmap myBitmap = BitmapFactory.decodeFile(APP.DIR_APP + APP.IMAGE + "/ok.png");
Drawable mDrawable = new BitmapDrawable(getResources(), myBitmap);
ImageSpan imageSpan = new ImageSpan(mDrawable);
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(contentText.getText());
String imgId = "[img=1]";
int selStart = contentText.getSelectionStart();
builder.replace(contentText.getSelectionStart(), contentText.getSelectionEnd(), imgId);
builder.setSpan(imageSpan, selStart, selStart + imgId.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
contentText.setText(builder);
此路径APP.DIR_APP + APP.IMAGE + "/ok.png"
是正确的,我检查与file.exists()
和真正的回报,但我不没有选择图片到编辑文字
答
别忘了打电话 mDrawable.setBounds(0, 0, myBitmap.getWidth(), myBitmap.getHeight())
。 或 mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
当前您将边界设置为0,0,0,0 - 因此,您看不到图像。它是零大小的。
如果要缩放图像,可以设置其他边界。
不要忘记缩放您的图像不同的屏幕密度。
+0
非常感谢。问题解决了 –
看到这个答案 - https://stackoverflow.com/a/3704545/5550161 –