7

I have a dotted line separator

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

    <!-- 
#17b851 #C7B299
     -->
    <stroke
       android:color="#9e9c85"
       android:dashWidth="10px"
       android:dashGap="10px" 
       />
</shape>

Right now its barely visible. How can I make it thick . I tried giving android:height="2px" & android:dashHeight="5px" but it didnt work.

Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126

4 Answers4

12

Stroke WIDTH must be smaller than the size HEIGHT.

(Stroke width is the width of the line. Size height is the height of the drawable. When drawn, the line is centered in the drawable. If size height <=stroke width, the line won't show up.)

dottedline.xml:

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

    <stroke
        android:dashGap="3dp"
        android:dashWidth="3dp"
        android:width="2dp"
        android:color="@android:color/black" />

    <size android:height="3dp" />
</shape>

the layout xml:

<ImageView
        android:layerType="software"
        android:contentDescription="underline"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/dottedline" />
furnaceX
  • 567
  • 2
  • 8
  • 15
  • 3
    Alternatively, (without size height) the layout_height in the ImageView can be set to something larger than the stroke width and it should work too. – furnaceX Mar 04 '15 at 23:45
4

You can use stroke width,

android:width="3dp"

snapshot

enter image description here

user3243163
  • 408
  • 2
  • 14
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • @Justin works fine. if it does not work for you doesn't mean it will not work for others. And why is this downvoted – Raghunandan May 07 '14 at 03:48
  • @Justin On what basis have you come to the conclusion that this does not work. And where is your code that does not work?? If it does not work it would not have been accepted – Raghunandan May 07 '14 at 03:55
  • This doesn't work for me either. The dashed line is correctly displayed in layout editor but invisible on the device. It also doesn't help to set the layerType to software, which is a common fix. – Julian Sievers Jun 06 '14 at 11:44
  • @McLovin does work for me. other than that i don't know much and post what you have done and on what versions did you try – Raghunandan Jun 06 '14 at 11:50
  • @McLovin if it does not work you need to be more specific. There is also other solution where you can draw a dotted line on the canvas – Raghunandan Jun 06 '14 at 11:52
2

use like this it is use full And THIS DOTTED LINE IN ANDROID

EDIT : Here is Answer

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

   <solid android:color="#fdfdfd" >
   </solid>

 <stroke
  android:dashGap="5px"
  android:dashWidth="5px"
  android:width="2dp"
  android:color="@color/scoreColor" >
</stroke>

</shape>

in xml file use this

NOTE : Note: With out this line in Higher versions not working android:layerType="software"

 <View
    android:layout_width="match_parent"
    android:layout_height="5dip"
    android:background="@drawable/dash_line"
    android:layerType="software"
    android:orientation="vertical" />
Community
  • 1
  • 1
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
1

you can define a line like

<?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="8dp"
android:height="2px"
android:color="#E90C0C" />

</shape>

and use it in your view as

<View
    android:id="@+id/vDottedLine"
    android:background="@drawable/dotted"
    android:layout_width="match_parent"
    android:layout_height="2px"
    android:layerType="software" />
Radheshyam Singh
  • 479
  • 3
  • 10