我正在开发一个聊天应用程序,它具有在输入图像和放大器时拍摄相机图像的功能。然后将其发送给其他用户..
我做了什么。
"<!>Hello World<!> (While <!> is my image separator)"
现在我有一个将用<!>
替换的图像的URL数组。
我正在尝试使用毕加索库,但只在附加列表中替换了一个图像,即(Hello World(-image is here))
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(message.getMessage().contains("<!>")){
final String msg = message.getMessage();
Target target = new Target() {
@Override
public void onPrepareLoad(Drawable arg0) {
//Toast.makeText(getActivity(), "message", Toast.LENGTH_LONG).show();
}
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
final Drawable drawImage = new BitmapDrawable( mContext.getResources(), bitmap);
addImageBetweenText(drawImage, holder.message, msg);
}
@Override
public void onBitmapFailed(Drawable arg0) {
}
};
for(int k = 0; k < message.getURLS().size(); k++){
String url_str = message.getURLS().get(k).trim();
Picasso.with(mContext).load(url_str).transform(new CircleTransform()).into(target);
}
}
这是我在文本之间添加图像的功能。
private void addImageBetweenText(Drawable drawable, TextView tv, String msg) {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
//for (int i = -1; (i = msg.indexOf("<!>", i + 1)) != -1; ) {
int i = msg.indexOf("<!>");
String st = msg.substring(i+3, msg.length());
int selectionCursor = i;
SpannableStringBuilder builder = new SpannableStringBuilder(st);
builder.insert(selectionCursor, ".");
selectionCursor = i+".".length();
builder.setSpan(new ImageSpan(drawable),selectionCursor - ".".length(), selectionCursor, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(msg);
//}
//int selectionCursor = emojiconEditText.getSelectionStart();
}
我的问题?
(<!> Hello World (image is here))
<!>
..