2016-09-21 74 views
-4

我試過這裏指定的幾個答案,How do I make a dotted/dashed line in Android?如何使用xml繪製粗虛線?

但是線條都很薄。

我需要的是厚10倍的東西。感謝您從正確的答案閱讀

碼結果:

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.tester.MainActivity"> 

    <ImageView 
    android:layout_width="match_parent" 
    android:layout_height="20dp" 
    android:src="@drawable/dotted" 
    android:layerType="software"/> 
</RelativeLayout> 

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="10px" 
    android:dashWidth="10px" 
    android:width="10dp" 
    android:color="@android:color/black" 
    /> 
</shape> 

Thick dotted line

+0

這麼愚蠢的問題! – Piyush

+0

@Piyush,謹慎地闡述'愚蠢'的部分? –

回答

2

在下面的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="10dp"/> 
    </shape> 
+0

這對你有幫助嗎? @Short回答 –

+0

你定義了什麼形狀?你能發佈完整的XML嗎? –