found this solution !! check it from source ---> response source
How to add multiple layout elements
This is a problem that people may encounter when working with layouts on Android.
Suppose you want to place an image in the middle of a sentence. you can add a pair of TextView and ImageView, but if the horizontal space gets too small, the two TextViews will begin to wrap independently, which will look strange. You want the image to be part of your TextView and the whole sentence to wrap it around beautifully. To do this: * replace three objects with one Spannable TextView * use SpannableStringBuilder to add all your lines (do not forget to add an additional character (for example, a space), which will be replaced by your image) * and finally use setSpan (ImageSpan, begin, end , flag) in this builder, where ImageSpan is ImageSpan containing the popped snapshot of your image, the beginning is the index of the character you entered
And here is the code:
add android: bufferType = "spannable" to your TextView
SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(mContext.getText(R.string.part1)); int lengthOfPart1 = builder.length(); builder.append(" "); builder.append(mContext.getText(R.string.part2)); Drawable d = mContext.getResources().getDrawable(R.drawable.picasaIcon); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
Lenn Dolling Apr 04 2018-11-11T00: 00Z
source share