2016-12-29 101 views
2

我想用shape作虛線。形狀虛線,短劃線不起作用

這是我的XML:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="line"> 
      <stroke android:color="@color/grey_divider" 
       android:width="1dip" 
       android:dashWidth="5dip" 
       android:dashGap="13dip"/> 
     </shape> 
    </item> 
</selector> 

在我的設備我看到這一點: enter image description here 但我需要的東西是這樣的:

enter image description here

如何解決呢?

回答

4

試試這個

請在繪製一個XML文件中。(例如dashed_line.xml)

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

    <stroke 
     android:color="#C7B299" 
     android:dashWidth="10px" 
     android:dashGap="10px" 
     android:width="1dp"/> 
</shape> 

現在在佈局中使用的XML文件。在一些視圖

android:background="@drawable/dashed_line" 
+0

使用 –

+0

+0

android:layerType =「software」 - 即使使用我的XML,只有這一行可以幫助我。作爲答案請教 – Artem