Android – Display Images inside Textview
Hello Readers,
While designing we may get a situation where we may have to display a image near text. For example
– Here is your Reward.
In Android, to display like this, we may use a Imageview followed by a Textview. The xml code may be
<LinearLayout android:id="@+id/layout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:id="@+id/dollar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/dollar" android:contentDescription="@string/img" /> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/rewardtext"/> </LinearLayout>
But the simple way to do this is, use the following code.
<TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/rewardtext" android:drawableLeft="@drawable/dollar"/>
Just adding a line android:drawableLeft=”@drawable/dollar” places the image left of the Textview. We can also use drawableRight,drawableTop,drawableBottom and place the image easily inside a Textview.
Related Posts
Nagarajan
View Nagarajan's Profile
Latest posts by Nagarajan (see all)
- Random Image viewer using AngularJS - June 30, 2016
- Building your first AngularJS app – Shopping list - June 22, 2016
- How to use Cookies in AngularJS - October 20, 2015
HOW TO SET IMAGE BETWEEN A STRING LIKE And*oid here * is a image (for refference only)