vxh.viet
4/8/2020 - 11:16 AM

Android - Horizontal and Vertical dash line

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>