Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw vertical dotted line

Tags:

android

I want to draw a vertical dotted line in xml, using shape.

I used this example:

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

<size
android:height="400dp"
android:width="4dp"/>

<stroke
        android:color="#000000"
        android:dashWidth="100dp"
        android:dashGap="10dp" />
</shape>

Then:

<View android:id="@+id/vertical_line"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/dotted_line"
      android:layout_marginLeft="27dp"/>

But it doesn't work. How can I do it?

like image 724
Igor Bykov Avatar asked Nov 04 '13 08:11

Igor Bykov


People also ask

How do I make a vertical dotted line in CSS?

You can use border-left or border-right properties to make a vertical line. In order to determine the height of an element, the height property is used. In order to determine the position of a vertical line, using the position property.


1 Answers

I tried a few things, I liked the drawable solutions and found that this worked.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:top="-8dp"
    android:bottom="-8dp"
    android:left="-8dp">
    <shape>
        <solid android:color="@android:color/transparent"/>
        <stroke
            android:width="4dp"
            android:color="#df0000"
            android:dashGap="4dp"
            android:dashWidth="4dp"/>
    </shape>
</item>
</layer-list>

The trick is the negative top bottom and left values as these are set outside of the object now, leaving a single dashed line.

Its used in the following view.

<View
android:layout_width="4dp"
android:layout_height="match_parent"
android:background="@drawable/dash_line_vertical"
android:layerType="software" />
like image 90
Duncan Hoggan Avatar answered Sep 21 '22 23:09

Duncan Hoggan