android - 形状虚线,破折号不起作用

标签 android android-shape

我想使用 shape 制作虚线。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="line">
            <stroke android:color="@color/grey_divider"
                android:width="1dip"
                android:dashWidth="5dip"
                android:dashGap="13dip"/>
        </shape>
    </item>
</selector>

在我的设备上我看到了这个: enter image description here 但我需要这样的东西:

enter image description here

如何解决?

最佳答案

试试这个

在drawable中制作一个xml文件。(例如dashed_line.xml)

<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>

现在在您的布局中使用此 xml 文件。

android:background="@drawable/dashed_line"

关于android - 形状虚线,破折号不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41378934/

相关文章:

android - 在android中使用 picasso 库下载base64编码图像

android - main.dart 中的脚手架未编译

android - 如何在android中构建梯形形状?

android - ShapeableImageView 的笔画被边框切割

java - 在运行时传递参数 Dagger 2

java - 如何从 WebView 下载图像

android - 在 LinearLayout 上仅添加顶部和底部边框

java - 在 fragment 中绘制多对象图

java - 六边形 ImageView 圆角

android - 我可以让我的应用程序与 Simtool Kit 对话以确定当前的资费计划和 SIM 中的余额吗?