我想在android中的edittext中添加带有imageview的多个textview。我可以通过以下代码在android中的edittext中添加一个带有imageview的textvew。
ClickableSpan clickSpan = new ClickableSpan() {
@Override
public void onClick(View view) {
Log.v("clicked", view.getClass().getSimpleName());
// int i = ((EditText) view).getSelectionStart();
// int j = ((EditText) view).getSelectionEnd();
// phoneNum.getText().replace(Math.min(i, j ),
// Math.max(i, j ), "", 0, "".length());
}
};
final SpannableStringBuilder sb = new SpannableStringBuilder();
TextView tv = createContactTextView(contactname);
View view1 = getLayoutInflater().inflate(R.layout.contact_layout,null);
TextView tv1 = (TextView) view1.findViewById(R.id.contactName);
tv1.setText(contactname);
BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(view1);
bd.setBounds(0, 0, bd.getIntrinsicWidth(),bd.getIntrinsicHeight());
sb.append(contactname + ",");
sb.setSpan(new ImageSpan(bd), sb.length()-(contactname.length()), sb.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
autoCompleteTextView.setMovementMethod(LinkMovementMethod.getInstance());
sb.setSpan(clickSpan, sb.length(),
sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
autoCompleteTextView.setText(sb);
public TextView createContactTextView(String text){
TextView tv = new TextView(this);
tv.setText(text);
tv.setTextSize(20);
tv.setBackgroundResource(R.color.bubble);
tv.setCompoundDrawablesWithIntrinsicBounds(0, 0,android.R.drawable.presence_offline, 0);
return tv;
}
public static Object convertViewToDrawable(View view) {
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
view.measure(spec, spec);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.translate(-view.getScrollX(), -view.getScrollY());
view.draw(c);
view.setDrawingCacheEnabled(true);
Bitmap cacheBmp = view.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
view.destroyDrawingCache();
return new BitmapDrawable(viewBmp);
}
如何使用imageview添加多个textview,如下面的布局?
我使用autocompletetextview完成了这项工作。在使用imageview插入一个textview后,将停止autocompletetextview的建议。如何再次启动autocompletetextview的自动建议?如何在autocompletetextview中插入带有imageview的多个textview?
2: