了解android复杂的形状绘图

时间:2013-10-18 08:10:35

标签: android shapes android-drawable

我想要一个由圆圈和直线组成的形状。我可能只是不明白这里的工作方式。

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

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

这不会按预期创建垂直线,它会为我创建一条水平线:horizontal line。每当我将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>

结果现在为vertical line

好的,所以,我不明白,但不管怎样。让我们添加一个圆圈,以便我得到这样的结果:vertical line with circle

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

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

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

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

1 个答案:

答案 0 :(得分:1)

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