Android 上的 TextView 下画线

发布于 2025-01-07 02:56:38 字数 208 浏览 1 评论 0原文

我有一个动态添加文本视图的布局,我想用一条线分隔每个文本视图。

像这样的事情:

TextView
 -----------------
TextView
 -----------------
TextView
 -----------------

我找到了给文本加下划线的方法,但我想画一条固定大小的线而不是给文本加下划线。

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 to draw a line with a fixed size not underline the text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

残疾 2025-01-14 02:56:38

这是最简单且最类似于在 HTML 中使用


标记的方法:

将其放入 XML 布局中您想要线条的位置:

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

这将在整个屏幕上绘制一条 1 dp 粗的白线屏幕。如果你希望它是固定宽度,只需将layout_width更改为你想要的dp大小即可。将背景更改为您选择的 HTML 颜色代码。

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.

没有心的人 2025-01-14 02:56:38

只需添加此样式

style="?android:listSeparatorTextViewStyle"

到您的TextView

just add this style:

style="?android:listSeparatorTextViewStyle"

to your TextView

謸气贵蔟 2025-01-14 02:56:38

如果您想以编程方式添加,请执行以下操作:

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

或者您可以将其添加到 strings.xml:

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

或:

SpannableString spannableStringObject= new SpannableString("Your text here");
spannableStringObject.setSpan(new UnderlineSpan(), 0, 
spannableStringObject.length(), 0);
textView.setText(spannableStringObject);

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);
无言温柔 2025-01-14 02:56:38

你可以建立一个ListView,它有一个分隔线,并且可以动态添加行。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文