Dotted line separator with custom thickness

2019-03-30 12:50发布

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.

4条回答
叼着烟拽天下
2楼-- · 2019-03-30 13:07

You can use stroke width,

android:width="3dp"

snapshot

enter image description here

查看更多
萌系小妹纸
3楼-- · 2019-03-30 13:22

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" />
查看更多
Juvenile、少年°
4楼-- · 2019-03-30 13:23

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" />
查看更多
该账号已被封号
5楼-- · 2019-03-30 13:27

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" />
查看更多
登录 后发表回答