I am trying to display a blue line next to a block of text, pretty much like this:
Here's my code:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/blue_line" />
blue_line is a jpg file. a blue rectangle. it displays in its original size regardless of the text in the textview. how can i adjust its height dynamically according to the height of the text? like make it shorter when theres little amount of text and longer when there's more text....
Try as below...
I Created a class that extends
TextView
, and resize the drawables inonPreDrawListener
.You can try doing it in code by setting bounds for the image
You need to make a one horizontal XML layout that has the blue line left and a textview right. Than use that layout like an item and make a ListView of those items. Something like here, but a bit simpler
Unfortunately, setBounds was not working for me so I had to do a workaround.
It is not the best solution regarding performance because new bitmap is created, but still works.
The best way to do this is to wrap your drawable in an xml drawable file and set it as a drawable in your text view as follows:
Drawable XML File:
TextView in XML: