draw line under TextView on Android

后端 未结 4 1721
野性不改
野性不改 2021-02-07 00:05

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

Something like that:

TextView


TextView


<
相关标签:
4条回答
  • 2021-02-07 00:43

    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.

    0 讨论(0)
  • 2021-02-07 00:52

    just add this style:

    style="?android:listSeparatorTextViewStyle"
    

    to your TextView

    0 讨论(0)
  • 2021-02-07 00:56

    If you want to add programmatically then do this:

    mTextView.setPaintFlags(mTextView.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG);
    

    or you can add this to strings.xml:

    <string name="your_string_here"><u>This is an underline</u>.</string>
    

    or :

    SpannableString spannableStringObject= new SpannableString("Your text here");
    spannableStringObject.setSpan(new UnderlineSpan(), 0, 
    spannableStringObject.length(), 0);
    textView.setText(spannableStringObject);
    
    0 讨论(0)
  • 2021-02-07 01:01

    You can build a ListView, it has a divider, and you can add line dynamically。

    0 讨论(0)
提交回复
热议问题