制作使用XML定义一个三角形?角形、定义、XML

2023-09-12 04:06:54 作者:没有什么不可能的,相信自己,别让自己后悔。今天小编为初三学子

有没有办法,我可以在XML文件中指定一个三角形的方式?

Is there a way that I can specify a triangle shape in an xml file?

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="triangle">
  <stroke android:width="1dip" android:color="#FFF" />
  <solid android:color="#FFF" />
</shape>

我们能做到这一点的,路径形状的东西?我只是需要一个等边三角形。

can we do this with a path shape or something? I just need an equilateral triangle.

感谢

推荐答案

在这个帖子我介绍了如何做到这一点。这里是XML定义三角:

In this post I describe how to do it. And here is the XML defining triangle:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <rotate
            android:fromDegrees="45"
            android:toDegrees="45"
            android:pivotX="-40%"
            android:pivotY="87%" >
            <shape
                android:shape="rectangle" >
                <stroke android:color="@color/transparent" android:width="10dp"/>
                <solid
                    android:color="@color/your_color_here" />
            </shape>
        </rotate>
    </item>
</layer-list>

请参考我的文章,如果事情是不明确或者你需要解释它是如何构建的。它旋转的切口矩形:)这是非常聪明和好工作的解决方案。

Refer to my post if something is unclear or you need explanation how it is built. It is rotated an cutout rectangle :) it is very smart and well working solution.

编辑: 创建一个箭头指向像 - >使用:

to create an arrow pointing like --> use:

...
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="13%"
android:pivotY="-40%" >
...

和创建一个箭头指向像&LT; - 使用:

And to create an arrow pointing like <-- use:

android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="87%"
android:pivotY="140%" >