Skip to content

Instantly share code, notes, and snippets.

@vxhviet
Created April 8, 2020 11:16
Show Gist options
  • Save vxhviet/6cd3665a8e5561390cc7645f5e62767a to your computer and use it in GitHub Desktop.
Save vxhviet/6cd3665a8e5561390cc7645f5e62767a to your computer and use it in GitHub Desktop.

Android - Horizontal and Vertical dash line

SOURCE, SOURCE

Horizontal dash line:

<?xml version="1.0" encoding="utf-8"?>
<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="1dp"/>
</shape>

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

layerType might not be neccesary, visit first link for more info.

Vertical dash line:

If the View has 1dp width then just rotating your horizontal line is not enough. The vertical line’s length will be 1dp as it is drawn horizontally first, then rotated. Here is a trick to solve this problem:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:left="-300dp"
        android:right="-300dp">
        <rotate
            android:drawable="@drawable/dash_line_divider_horizontal"
            android:fromDegrees="90"
            android:toDegrees="90"/>
    </item>
</layer-list>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment