具有自定义厚度的虚线分隔线

Vih*_*rma 5 xml android paint stroke

我有一个虚线分隔符

<?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>
Run Code Online (Sandbox Code Playgroud)

现在它几乎看不到.我怎样才能让它变厚.我尝试给android:height ="2px"和android:dashHeight ="5px",但它没有用.

fur*_*ceX 8

行程WIDTH必须小于HEIGHT的大小.

(笔划宽度是线条的宽度.尺寸高度是可绘制的高度.绘制时,线条在可绘制的中心.如果尺寸高度<=笔划宽度,则线条不会显示.)

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>
Run Code Online (Sandbox Code Playgroud)

布局xml:

<ImageView
        android:layerType="software"
        android:contentDescription="underline"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/dottedline" />
Run Code Online (Sandbox Code Playgroud)

  • 另外,也可以将ImageView中的layout_height(没有大小高度)设置为大于笔触宽度的值,并且它也应该起作用。 (2认同)

Rag*_*dan 4

您可以使用描边宽度,

android:width="3dp"
Run Code Online (Sandbox Code Playgroud)

快照

在此输入图像描述