Android 上的 TextView 下画线
我有一个动态添加文本视图的布局,我想用一条线分隔每个文本视图。
像这样的事情:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是最简单且最类似于在 HTML 中使用
标记的方法:将其放入 XML 布局中您想要线条的位置:
这将在整个屏幕上绘制一条 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:
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 thebackground
to the HTML color code of your choice.只需添加此样式:
到您的TextView
just add this style:
to your TextView
如果您想以编程方式添加,请执行以下操作:
或者您可以将其添加到 strings.xml:
或:
If you want to add programmatically then do this:
or you can add this to strings.xml:
or :
你可以建立一个ListView,它有一个分隔线,并且可以动态添加行。
You can build a ListView, it has a divider, and you can add line dynamically。