1

我已经创建了一条 xml 虚线,如如何在 Android 中制作虚线/虚线?. 如果我将它用作我的 TextView 的背景,它就会显示出来。

<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 中的文本下方。请帮忙。

4

2 回答 2

3

使用以下代码制作带有虚线的文本视图。在名为 dotted.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" />
于 2013-09-23T05:37:38.697 回答
0
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" />
于 2013-09-23T05:18:47.287 回答