Dotted line separator with custom thickness

2019-03-30 13:03发布

问题:

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.

回答1:

You can use stroke width,

android:width="3dp"

snapshot



回答2:

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" />


回答3:

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" />


回答4:

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" />