【问题标题】:Android Dash Lines Not ShowingAndroid 虚线不显示
【发布时间】:2015-07-07 15:36:47
【问题描述】:

请注意,我确实在 SO 上引用了创建短划线问题,并通过 Google 进行了各种搜索......无论如何,问题就是这样。我无法通过 xml 绘制虚线(可以使用 DashPathEffect 但不想继续这样做)。这是我使用的 dash drawable (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>

现在,在 xml 中为 imageview 实现:

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

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

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

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

【问题讨论】:

    标签: java android xml user-interface


    【解决方案1】:

    尝试在您的ImageView 中将software 设置为layerType

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

    【讨论】:

    • 是的,我在 xml 和编程中都试过了。什么都没有。
    • 好的,将此设置保存在 xml 中并尝试将您的 shape 包装到,例如 selector 中,然后判断是否有效。
    • 我尝试将形状包装到选择器中,但这也不起作用(将 layerType 保留给软件)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    相关资源
    最近更新 更多