3

这是我下面的代码,它在 textview 的中心显示虚线我想在 textview 下方显示,如下所示:

带有虚线的文本视图

如何将其更改为显示在 textview 虚线下方

<?xml version="1.0" encoding="utf-8"?>

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent" >

   <TextView

       android:id="@+id/apprentTemp"
       android:textColor="#000000"
       android:background="@drawable/dotted"
       android:paddingLeft="10dp"
       android:gravity="left"/>

    <TextView
      android:id="@+id/localTime"
      android:textColor="#000000"
      android:background="@drawable/dotted"
      android:gravity="center"/>

</TableRow>

       <----   dashed.xml   -->

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

   <stroke
       android:color="#000000"
       android:dashWidth="5px"
       android:dashGap="5px" />

</shape>
4

5 回答 5

5

利用

android:drawableBottom="@drawable/dotted"

反而

android:background="@drawable/dotted"

编辑:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:left="-5dp"
    android:right="-5dp"
    android:top="-5dp">
    <shape
        android:shape="rectangle">

        <stroke
            android:width="1dp"
            android:dashGap="5dp"
            android:dashWidth="5dp"
            android:color="@android:color/black" />
    </shape>
</item>

</layer-list>
于 2013-08-29T10:14:13.740 回答
5

尝试这个

虚线.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >

    <stroke
        android:dashGap="2dip"
        android:dashWidth="2dip"
        android:color="@android:color/black" />

    <size android:width="60dp"
          android:height="6dp"/>

</shape>

然后使用

android:drawableBottom="@drawable/dashed"  

在你的TextView

代替

android:background="@drawable/dotted"

输出:

Line_below_textview

于 2013-08-29T10:35:01.157 回答
0

我就是这样做的。一点点修改和工作。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:gravity="center_vertical"
  >
    <shape
        android:shape="line">
        <stroke
            android:width="1dp"
            android:dashGap="0dp"
            android:dashWidth="5dp"
            android:color="@color/statusLight" />
    </shape>
</item>

在此处输入图像描述


只需将 android:dashGap 添加到您想要的任何值。

于 2018-10-13T06:38:22.023 回答
0

如果要在视图中心显示虚线,请使用以下代码。喜欢 -------- 或继续 ----------

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:left="-5dp"
    android:right="-5dp"
    android:gravity="center_vertical">
    <shape
        android:shape="line">
        <stroke
            android:width="1dp"
            android:dashGap="2dp"
            android:dashWidth="5dp"
            android:color="@android:color/darker_gray" />
    </shape>
</item>
于 2020-10-13T04:17:28.953 回答
-1

尝试这个

  <TextView
 android:id="@+id/total"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:gravity="right"
 android:text="TextView" 
 android:drawableBottom="@drawable/dividerline"/>

如下制作一个xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <size
        android:height="1dp"
        android:width="70dp" />

    <solid android:color="@android:color/black" />

</shape>
于 2013-08-29T10:11:40.987 回答