I am working with a restaurant application and i want Veg Non-Veg image just after the food name. I have used relative layout but couldn't able to achieve. See Image I want to achieve this. Thanks in advance.
Asked
Active
Viewed 1,017 times
1
-
have you tried android:drawableRight =@your_image ?? – Arpit Ratan Jun 13 '16 at 16:03
-
No idea man.. i didn't – Arpit Ratan Jun 13 '16 at 16:03
-
yes i have tried that.. but that is showing image at the end of textview. – Manpreet Jun 13 '16 at 16:03
-
2I guess someone downvoted you because you haven't showed your code, a try or something. – DAVIDBALAS1 Jun 13 '16 at 16:04
-
You can split the last line of the text view to another text view, put it below the first textview and then the image to it's right. I don't know if it's the best solution though. – DAVIDBALAS1 Jun 13 '16 at 16:05
-
but sometimes food name will only cover single line of text view – Manpreet Jun 13 '16 at 16:08
-
1I wonder why people downvote without any prior reason, we know some are pros over here but most people who are here are trying to learn something. Anyway @ManpreetSingh, next time show us some snippet of your code. – Clement Osei Tano Jun 13 '16 at 16:19
-
Check this out: http://stackoverflow.com/questions/15352496/how-to-add-image-in-a-textview-text – maja89 Jun 13 '16 at 17:22
-
thanks everyone for motivating me.. :) and thanks for your support – Manpreet Jun 14 '16 at 06:10
1 Answers
1
Try using a custom view like this one;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/item_name"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/item_image"/>
</LinearLayout>
Then your application will need an adapter to display the contents in the list or whatever view you want to display.

Clement Osei Tano
- 812
- 7
- 9
-
Thanks for your reply but again image is at the and of text view, i can achieve this using drawable right.. – Manpreet Jun 14 '16 at 06:16
-
-
-
Then you might want to try drawing your custom view, in this view, you make the textview and imageview as one view and the image should come at the last point of the textview. – Clement Osei Tano Jun 18 '16 at 19:38