0

我想要一个由圆和线组成的形状。我可能只是不明白这里的事情是如何运作的。

首先,我考虑通过旋转线条形状来创建一条垂直线。

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="90"
    >
    <shape android:shape="line">
        <stroke
            android:width="2dp"
            android:dashWidth="2dp"
            android:dashGap="4dp"
            android:color="@android:color/holo_blue_bright"
            />
    </shape>
</rotate>

这不会像预期的那样创建一条垂直线,它会为我创建一条水平线:水平线。每当我将fromDegrees属性更改为 90 时,我都有一个垂直属性。toDegrees只是被忽略了。

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:toDegrees="190"
    >
    <shape android:shape="line">
        <stroke
            android:width="2dp"
            android:dashWidth="2dp"
            android:dashGap="4dp"
            android:color="@android:color/holo_blue_bright"
            />
    </shape>
</rotate>

结果是现在垂线

好的,所以,我不明白,但无论如何。让我们添加一个圆圈,以便我得到如下内容:带圆圈的垂直线

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate android:fromDegrees="90">
            <shape android:shape="line">
                <stroke
                    android:width="2dp"
                    android:dashWidth="2dp"
                    android:dashGap="4dp"
                    android:color="@android:color/holo_blue_bright" />
            </shape>
        </rotate>
    </item>
    <item>
        <shape android:shape="oval">
            <stroke android:color="#000" android:width="2dp" />
            <solid android:color="@android:color/white" />
        </shape>
    </item>
</layer-list>

我得到的只是一个圆圈:圆圈 考虑到圆圈填充了形状的整个大小,在整条线上绘制,我添加了一个scale元素,使圆圈缩小 50%。

<scale
    android:scaleWidth="50%"
    android:scaleHeight="50%">
    <shape android:shape="oval">
        <stroke android:color="#000" android:width="2dp" />
    </shape>
</scale>

在那之后,圆圈就消失了,我又只得到了那条线。那么,任何人都可以帮助我理解,这里发生了什么?

4

1 回答 1

1

看看这里的答案:https ://stackoverflow.com/a/15239304/1064689 旋转度数是指动画。

于 2013-12-18T21:41:31.657 回答