2017-09-25 103 views
0

我想在我的视图上显示虚线“---”。我在stackoverflow上搜索了很多例子,并使用类似的可绘制代码并调用我的视图。在我的IDE上显示虚线,但是当我在设备上运行它时,它显示出平面直线。请在这方面建议我为什么发生这种情况。在xml中显示而不是虚线的平面线android

我可绘制dotted.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="line"> 
    <stroke 
     android:dashGap="3dp" 
     android:dashWidth="2dp" 
     android:width="1dp" 
     android:color="@color/black" /> 
</shape> 

我查看我在哪里调用它。

<View 
     android:layout_width="fill_parent" 
     android:layout_height="10dp" 
     android:background="@drawable/dotted_line" 
     android:layout_marginTop="5dp"/> 

回答

1

如果您查看不工作然后尝试使用的ImageView它的工作

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="10dp" 
    android:src="@drawable/dotted_line" 
    android:layout_marginTop="5dp" 
    android:layerType="software" /> 
+0

这就是很多它的工作原理。不知道逻辑为什么它不适用于View,但它的工作原理。 –

+1

我也在努力解决这个问题,但找不到 –