gpt4 book ai didi

java - Android 虚线不显示

转载 作者:太空宇宙 更新时间:2023-11-03 10:18:19 24 4
gpt4 key购买 nike

请注意,我确实在 SO 上以及通过 Google 进行的各种搜索中提到了创建虚线问题……无论如何,问题就是这样。我无法通过 xml 绘制虚线(可以使用 DashPathEffect 但不想继续这样做)。这是我使用的破折号可绘制对象 (dash_line.xml):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

<stroke
android:color="@color/whiteColor"
android:dashWidth="10dp"
android:width="10dp"
android:dashGap="4dp"/>
</shape>

现在,然后是 imageview 的 xml 实现:

<ImageView
android:id="@+id/dash_test"
android:layout_width="200dp"
android:layout_height="10dp"
android:background="@drawable/dash_line"/>

我正在使用 Android API 18。我什至通过设置层类型(在 xml 中和以编程方式尝试)在 list 中甚至在 View 本身上禁用硬件加速。我通过查看 dashView.isHardwareAccelerated() 进行了验证,它是错误的。关于我缺少的东西有什么想法吗?

编辑:顺便说一句,我可以画实线,所以我知道这不是分层问题。

编辑:一种解决方法是使用 PathDashEffect。虽然你会遇到无法在图像上绘制的问题(我需要这样做)。所以...仍然想要一个 xml 解决方案。

最佳答案

尝试在 ImageView 中将 software 设置为 layerType:

<ImageView
android:layerType="software"
...
/>

关于java - Android 虚线不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31273155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com