使用 XML 定义制作三角形? [英] Making a triangle shape using XML definitions?

查看:39
本文介绍了使用 XML 定义制作三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 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%" >
...

并创建一个像 <-- 一样的箭头,使用:

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

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

这篇关于使用 XML 定义制作三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆