Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

draw line under TextView on Android

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

like image 878
João Nunes Avatar asked Feb 21 '12 01:02

João Nunes


People also ask

How do you put a line under text on android?

Go to res > drawable > new > drawable resource file and create a new file and name it “dashed_underline. xml” and define all properties of the dashed line that we need. Later we will add this as the background of TextView. Below is the code for dashed_underline.

How do you add a line in TextView?

If you just want to add a line break in the form: textView. setText(string1+System. getProperty ("line. separator")+string2); then it works a treat, thank you!

How do you underline text in TextView?

You can also underline a portion of the text via code, it can be done by creating a SpannableString and then setting it as the TextView text property: SpannableString text = new SpannableString("Voglio sottolineare solo questa parola");text. setSpan(new UnderlineSpan(), 25, 6, 0);textView. setText(text);


1 Answers

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.

like image 122
koopaking3 Avatar answered Sep 25 '22 10:09

koopaking3