在android TextView中使用xml虚线

在android TextView中使用xml虚线,android,android-layout,android-linearlayout,android-relativelayout,textview,Android,Android Layout,Android Linearlayout,Android Relativelayout,Textview,我创建了一条xml虚线,如中所述。如果我用它作为文本视图的背景,它就会显示出来 <TextView android:id="@+id/segment" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/dotted_lines" android:gravity="left" android

我创建了一条xml虚线,如中所述。如果我用它作为文本视图的背景,它就会显示出来

<TextView
    android:id="@+id/segment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/dotted_lines"
    android:gravity="left"
    android:text="First segment"
    android:textSize="12sp" />

但如果我将其用作附带的绘图工具,则不会显示

<TextView
    android:id="@+id/segment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawableBottom="@drawable/dotted_lines"
    android:gravity="left"
    android:text="First segment"
    android:textSize="12sp" />

基本上,我对这两种方式都不在乎,除了:我需要在TextView中的文本下方显示虚线。请帮助。

试试这个。我认为textview高度可能会给您带来问题。
Try this. i think textview height might cause problem for you.
    <TextView
        android:id="@+id/segment"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:drawableBottom="@drawable/dotted_lines"
        android:gravity="left"
        android:text="First segment"
        android:textSize="12sp" />

使用以下代码创建带虚线的文本视图。 在名为domind.xml的可绘制文件夹中创建文件

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">

    <stroke
        android:color="#F59C51"
        android:width="2dp"
        android:dashGap="1dp"
        android:dashWidth="2dp"/>
</shape>

然后设置为textview的背景,如下所示

<TextView
    android:id="@+id/segment"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/dotted"
    android:gravity="left"
    android:text="First segment"
    android:textSize="12sp" />


我认为这可能会帮助您..如果TextView有多行,会发生什么?如果TextView有多行,会发生什么?