Reputation: 11532
How to combine text image text
inside TextView ?
I load text from values/strings.xml
but how to add at the middle od text one image icon.png
from drawable.
Upvotes: 0
Views: 2453
Reputation: 49797
Why don't you put something like this in your layout:
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivMiddle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_left"
android:layout_centerHorizontal="true"
android:layout_toLeftOf="@id/ivMiddle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_right"
android:layout_centerHorizontal="true"
android:layout_toRightOf="@id/ivMiddle"/>
</RelativeLayout>
Has the same effect and is a lot easier to do.
EDIT:
Or as ElDuderino suggested you can simply do this:
ImageSpan is = new ImageSpan(context, R.drawable.image);
SpannableString text = new SpannableString("Left Right");
text.setSpan(is, 4, 4, 0);
Upvotes: 1