draw line under TextView on Android

João Nunes picture João Nunes · Feb 21, 2012 · Viewed 34.8k times · Source

I have a layout that adds textviews dynamically and i want to divide each textview with a line.

Something like that:

TextView


TextView


TextView


I have found ways to underline the text, but i want draw a line with fix size not underline the text.

Can anyone help me out ?

Best Regards

Answer

koopaking3 picture koopaking3 · Feb 21, 2012

This is the simplest and most similar to using the <hr> tag in HTML:

Put this in your XML layout where you want the line:

<View 
   android:layout_width="fill_parent"
   android:layout_height="1dp"       
   android:background="#ffffff" />

This will draw a white line, 1 dp thick, across the screen. If you want it to be a fixed width, just change the layout_width to the dp size you want. Change the background to the HTML color code of your choice.