I am using SpannableStringBuilder to show image inside TextView. However, if the image will stay at the end of the line in TextView it just disappears. If I increase the size of the text it would be visible again. How can I fix it?
This is the code how I added the image inside TextView:
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.setSpan(new ImageSpan(createClusterBitmap(idOfAyat)), ssb.length() - 1, ssb.length(), 0);
itemViewHolder.kuranArabic.setText(ssb);
XML code of item:
<TextView
android:id="@+id/kuranArabic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/_4sdp"
android:fontFamily="@font/scheherazade"
android:gravity="center_horizontal"
android:textAlignment="center"
android:textColor="?attr/color2"
android:textSize="@dimen/_27sdp" />
I have attached two images. The first one is with an image that disappears when stays at end of the text view. The second one is visible when comes at the first position.
First Picture if StackOverflow's link doesn't work
Second Picture if StackOverflow's link doesn't work
P.S. I would appreciate any help. It is one of my first questions, don't judge me so strongly. :)
I have solved my problem by adding a flag called Spannable.SPAN_EXCLUSIVE_EXCLUSIVE to Spannable String Builder.
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.setSpan(new ImageSpan(image), ssb.length() - 3, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
itemViewHolder.kuranArabic.setText(ssb);