简体   繁体   English

在text int TextView中插入水平线

[英]Insert horizontal line in text int TextView

在此处输入图片说明 I have a plenty of lines to display in a single TextView . 我有很多行要显示在单个TextView中。 I get the text from database and then display it. 我从数据库中获取文本,然后显示它。 So I want to build the database with entries and horizontal lines in it. 因此,我想构建包含条目和水平线的数据库。 When I copy paste them. 复制时将其粘贴。 Only words get pasted and horizontal lines don't appear. 仅粘贴单词,不显示水平线。 I want to insert some horizontal lines at some points of the line like 我想在线条的某些点插入一些水平线,例如

Hello 你好


Hi I am fine 嗨我很好


There should be a divider like line that can be inserted at places I want . 应该在我想要的地方插入一个分隔线之类的分隔线。 Are there any escape sequences? 是否有任何转义序列? But it should be done in TextView text. 但是应该在TextView文本中完成。 Is there any trick to do it? 有什么窍门吗? I tried copy pasting the text with line from word but it only copies the text and not the line . 我尝试从word复制带有行的粘贴文本,但是它仅复制文本而不是行。 Are there any ways to do it like using the horizontal tag in html?? 有没有办法像在html中使用水平标记一样呢? Any help is highly appreciable.. 任何帮助都是非常明显的。

try below code 尝试下面的代码

 <View  android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="@android:color/black"/>

You could try to do some css inherited in the TextView: 您可以尝试在TextView中继承一些CSS:

myTextView.setText(Html.fromHtml("<span style="border....">Hello</span>"));

Edit: 编辑:

String dynamicText = "textGenerated";
String message = "<span style='border-bottom:1px solid'>" + dynamicText + "</span>";

myTextView.setText(Html.fromHtml(message));
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical" >

    <TextView
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="hello" >
    </TextView>

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="2dp"
                  android:background="@android:color/darker_gray"
                  android:padding="5dp">
    </LinearLayout>

    <TextView
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="hi I am Fine" >


    </TextView>

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="2dp"
                  android:background="@android:color/darker_gray"
                  android:padding="5dp">
    </LinearLayout>

</LinearLayout>

Add this layout below to your layout XML: 将以下布局添加到布局XML:

<LinearLayout android:layout_width="match_parent"
    android:layout_height="2dp"
    android:background="@android:color/darker_gray">
</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM