【问题标题】:using xml dotted line in android TextView在android TextView中使用xml虚线
【发布时间】:2013-09-23 13:37:38
【问题描述】:

我创建了一个 xml 虚线,如 How do I make a dotted/dashed line in 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 中的文本下方。请帮忙。

【问题讨论】:

标签: android android-layout android-linearlayout android-relativelayout textview


【解决方案1】:

使用以下代码制作带有虚线的文本视图。 在名为 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" />

【讨论】:

  • TextView 多行怎么办?
【解决方案2】:
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" />

【讨论】:

  • TextView 多行怎么办?
猜你喜欢
  • 2017-09-06
  • 1970-01-01
  • 1970-01-01
  • 2020-02-01
  • 1970-01-01
  • 2011-05-05
  • 2011-05-06
  • 2012-03-08
  • 1970-01-01
相关资源
最近更新 更多