2017-09-25 49 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

我也在努力解決這個問題,但找不到 –