Reputation: 167
Actually I have TextView with some text. I need to insert an image insight this text. Please suggest the best way to do that. Should be supported on different display sizes.
Upvotes: 1
Views: 1411
Reputation: 13815
If want to do it via xml
add this attribute to TextView element
android:background="@drawable/icon"
If at runtime programatically
TextView tv = (TextView)findViewById(R.id.textView);
tv.setBackgroundDrawable(drawable);
or
tv..setBackgroundResource(resid);
Upvotes: 0
Reputation: 128428
Are you talking about to display image inside the TextView at either Top/Bottom/Right/Left side, if yes then:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, DemoExampleActivity!"
android:drawableLeft="@drawable/icon"
android:drawableRight="@drawable/icon"
android:drawablePadding="10dip"/>
output:
Upvotes: 1
Reputation: 3081
You can set the image as the background for the TextView
like this:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text to be displayed"
android:background ="@drawable/your_image"
/>
Good luck, Arkde
Upvotes: 0