[英]Understanding android complex shape drawing
I want to have a shape consisting of a circle and a line. 我想要一个由圆形和直线组成的形状。 I probably just don't understand how things work here.
我可能只是不明白这里的工作方式。
First, I thought about creating a vertical line by rotating a line shape. 首先,我考虑过通过旋转线形来创建垂直线。
<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>
This does not create a vertical line as expected, it creates a horizontal line to me: 这不会像预期的那样创建垂直线,而是为我创建了一条水平线:
.
。 Whenever I change the
fromDegrees
attribute to 90, I have a vertical one. 每当我将
fromDegrees
属性更改为90时,我就有一个垂直的属性。 toDegrees
is just ignored. 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>
The result is now 结果是现在
.
。
Ok, so, I don't understand, but whatever. 好吧,所以,我听不懂,但是随便。 Let's add a circle so that I get something like this:
让我们添加一个圆圈,以便得到如下内容:
<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>
What I get is just a circle: 我得到的只是一个圆圈:
Having thought that the circle fills the entire size of the shape, being drawn over the entire line, I added a
scale
element to have the circle scaled 50% down. 考虑到圆会填满形状的整个大小(在整条直线上绘制),因此我添加了一个
scale
元素,以使圆缩小50%。
<scale
android:scaleWidth="50%"
android:scaleHeight="50%">
<shape android:shape="oval">
<stroke android:color="#000" android:width="2dp" />
</shape>
</scale>
After that, the circle just disappeared and I got only the line again. 在那之后,圆圈消失了,而我又只得到了那条线。 So, can anyone help me understand, what's going on here?
那么,有人可以帮助我了解一下,这是怎么回事?
在这里看看答案: https : //stackoverflow.com/a/15239304/1064689旋转度是指动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.