2

我正在开发一个 Android 应用程序,我想在其中使用虚线 XML 作为布局中的分隔符。为此,我为此使用了不同的可绘制对象,而是制作了一条虚线,它正在制作一条线。

我的drawable如下:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke
        android:color="#FF404040"
        android:width="1dp"
        android:dashGap="3dp"
        android:dashWidth="1dp"
    />
    <size
        android:height="3dp"
    />
</shape>
4

4 回答 4

11

GL 模式不支持虚线。所以添加

android:layerType="software"

例如

<ImageView
    android:layerType="software" // add here
 ...

在您的 xml 布局中查看或以编程方式作为

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

或者像这样关闭硬件加速:

android:hardwareAccelerated="false"
于 2015-04-25T09:36:07.743 回答
2
use Below code

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:toDegrees="90" >

    <shape android:shape="line" >

        <stroke

            android:width="1dp"
            android:dashGap="6px"
            android:dashWidth="6px"
            android:color="#C7B299" />
    </shape>

</rotate>
于 2015-04-25T09:51:45.380 回答
1

可能这对你有帮助..

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

    <stroke
       android:color="#C7B299"
       android:dashWidth="10px"
       android:dashGap="10px" />
</shape>

只是参考这个.. 我如何在Android中制作虚线/虚线?

于 2015-04-25T09:37:55.643 回答
1

尝试这个

<?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="line">
        <stroke
            android:color="#FF404040"
            android:width="5dp"
            android:dashGap="10dp"
            android:dashWidth="10dp"
            />

    </shape>
于 2015-04-25T09:38:37.730 回答