Anand Savjani Anand Savjani - 3 months ago 34
Android Question

Add ImageView after text

enter image description here

I want to achieve this functionality . Please provide suggestion for it.

Answer

Try this, this adds a drawable in a TextView after text.

TextView text=(TextView)findViewById(R.id.textView);
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append("This is text with image!").append(" ");
Drawable myIcon = getResources().getDrawable(R.drawable.ic_new);
myIcon.setBounds(0, 0, test.getLineHeight(),test.getLineHeight());
builder.setSpan(new ImageSpan(myIcon, ImageSpan.ALIGN_BASELINE),builder.length() - 1, builder.length(), 0);
text.setText(builder);
Comments