I'm trying to convert text to an image by changing each character of this text to an image, but I faced the word-break issue, I would like to make it return to a new line
e.g :

Should be :
Do it for
the
Aesthetic
Here's my code :
MyDynamicDrawableSpan class :
public class MyDynamicDrawableSpan extends DynamicDrawableSpan {
private final Context mContext;
private final Drawable drawable;
public MyDynamicDrawableSpan(Context context, Drawable drawable) {
mContext = context;
this.drawable = drawable;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public Drawable getDrawable() {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
return drawable;
}
}
The necessary methods:
public void insert(String text, int start, int end, Drawable drawable) {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
MyDynamicDrawableSpan spannable = new MyDynamicDrawableSpan(getApplicationContext(), drawable);
message.setSpan(spannable, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
private void insertImageSpan(String str) throws IOException {
addText(generateRansomNotText(str));
}
private void addText(SpannableString generateRansomNotText) {
textView.setText(generateRansomNotText);
}
public SpannableString generateRansomNotText(String text) throws IOException {
for (int i = 0; i < text.length(); i++) {
Drawable drawable = getLetterDrawable(getApplicationContext(), "" + text.charAt(i));
String str = "" + text.charAt(i);
insert(str, i, text.length(), resize(drawable));
}
return message;
}
private Drawable resize(Drawable image) {
int width = image.getIntrinsicWidth() > 40 ? image.getIntrinsicWidth() : min_size;
int height = image.getIntrinsicHeight() > 40 ? image.getIntrinsicHeight() : min_size;
return ImageUtils.bitmap2Drawable(ImageUtils.scale(ImageUtils.drawable2Bitmap(image), width * multiple, height * multiple, false));
}
I tried to put : android:hyphenationFrequency="none"
to the TextView
, but it does not work