简体   繁体   中英

image with textview.setText and textview.append

I need some help. I have a screen where there is a textview. In the textview, i check some conditions and append some text to that textview. What i want is to insert an image on the left of each line. This is a single textview. Just like below. How can i do this? Thanks.

tv.setText("image here","\nAccount: " + booking.getAccount());
tv.append("image here",String.format("\t(Vehicle Type: %s)",booking.getVehicletype()));
tv.append("image here","\n\nTag: " + booking.getTag());
tv.append("image here","\n\nDate & Time: " + booking.getDate() + " - " + booking.getTime());
tv.append("image here","\n\nName: " + booking.getCustname());

i want is to insert an image on the left of each line

You cannot do this. You can only put one drawable each side of a TextView . (ie bottom, top, left, right), by setCompoundDrawablesWithIntrinsicBounds(...)

An option for your case would be using a vertical LinearLayout and add those TextViews as its child. Those can also hold a drawable at their's left side by the method above.

use following code in layout.xml file

android:drawableLeft="@drawable/page1"(drawable resource)

you can set image any side of textview using this attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM