1

我已经创建了一个xml虚线,如How do I make a dotted/dashed line in Android?中所述。如果我使用它作为我的TextView的背景,它会显示出来。在android中使用xml虚线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" /> 

但是,如果我使用它作为附带的drawable,它不会显示出来。

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

+1

我想这可能帮助you..http://stackoverflow.com/questions/10020466/android-4-0-sub-title-section-label-styling LQ = 1 –

回答

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" /> 
+1

应发生什么情况? TextView有多行? –

3

使用下面的代码可以用虚线制作textview。 名为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" /> 
+0

如果具有多行的TextView会发生什么情况? –

相关问题