I want to set the drawable image to the end of the text but it shows the end of the text view.
Here is my code
<TextView android:id="@+id/tv_overweight_messsage" android:layout_width="wrap_content" android:layout_height="wrap_content android:layout_marginTop="@dimen/activity_marginVertical_Large" android:gravity="center" android:text="dvdmnvkdnxknb vcnbvcxmnbxm,cbn,m vnnxmndxvbhddbv svbhzv" android:textColor="@color/required" android:textSize="@dimen/textSize_small" android:drawablePadding="@dimen/widget_padding" android:drawableRight="@drawable/img_infobn" android:visibility="gone" app:mfafont="@string/font_Questrial_Regular" tools:visibility="visible" />
Advertisement
Answer
You can embed an ImageSpan
in a SpannableString
and set the TextView
to display that. For example:
String text = "hello "; SpannableStringBuilder sb = new SpannableStringBuilder(text); ImageSpan imageSpan = new ImageSpan(context, R.drawable.my_icon); sb.setSpan(imageSpan, text.length() - 1, text.length()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);