I was wondering if it is possible to add textview inside imageview or vice-versa. Is it possible? If yes then how?
I want to make this at runtime
The simplest way I think is to setCompoundDrawables via XML attributes
android:drawableLeft
android:drawableTop
android:drawableRight
android:drawableBottom.
Example:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_navigation_chevron_right"
android:text="Next "
android:textSize="20dp" />
Result:

ImageSpan ispan = new ImageSpan(context, yourresourceid);
text.setSpan(ispan, index, index + strLength, 0);
OR
TextView textView = (TextView)findViewById( R.id.TextView );
Spannable spannable = (Spannable)textView.getText();
StyleSpan boldSpan = new StyleSpan( Typeface.BOLD );
spannable.setSpan( boldSpan, 41, 52, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
TextView textView2 = (TextView)findViewById( R.id.TextView2 );
SpannableStringBuilder ssb = new SpannableStringBuilder( "Here's a smiley " );
Bitmap smiley = BitmapFactory.decodeResource( getResources(), R.drawable.emoticon );
ssb.setSpan( new ImageSpan( smiley ), 16, 17, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
textView2.setText( ssb, BufferType.SPANNABLE );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With