Android uses shape to set the dividing line without displaying the problem (stepping on the pit)

Android uses shape to set the dividing line without displaying the problem (stepping on the pit)


It is necessary to set a dotted dividing line. First write the dotted line style in shape, and then set the View's android:background="@drawable/dottet_shape" to achieve it.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke android:color="#F4F4F4"
            android:width="0.8dp"
            android:dashGap="2dp"
            android:dashWidth="2dp"></stroke>
    <size android:width="1000dp"/>

</shape>

Among them, color is the dotted line format, width is the height of the dotted line, dashGap is the interval length, and dashWidth is the length of each grid of the dotted line.

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"   	 
    android:background="@drawable/dottet_shape"/>

It should be noted that View is different from view, and an error will be reported if lowercase is used. In addition, the android:layout_height="1dp" of the View must be greater than the android:width="0.8dp" of the shape. If the two are equal in size, the dotted line will not be displayed (this is a pit mark).

Guess you like

Origin blog.csdn.net/weixin_41046681/article/details/104890019