Android(安卓)svg 绘制三角形
16lz
2022-04-29
三角形作为一个基本的Shape,在Android中是不支持的。
以前我们这样来定义三角形:
<rotate android:fromDegrees="45" android:toDegrees="45" android:pivotX="-40%" android:pivotY="80%"> <shape android:shape="rectangle"> <solid android:color="#000000"/> shape> rotate>
将一个矩形旋转一定的角度得到三角形。说实话,这种方式一直都模模糊糊的,所以都拷贝别人代码。
当然也可以自定义View,画一个三角形。
不过今天来说说通过Vector标签(Android对svg的支持方式)来定义三角形:
<?xml version="1.0" encoding="utf-8"?><vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="24" android:viewportHeight="24" android:width="24dp" android:height="24dp"> <path android:pathData="m0 24 l12 -24 l12 24 z" android:fillColor="@color/material_red" />vector>
其中viewportWidth和viewportHeight属性用于申明坐标的大小,width和height属性标书drawable的大小。
android:pathData 中定位命令:
M = movetoL = linetoH = horizontal linetoV = vertical linetoC = curvetoS = smooth curvetoQ = quadratic Belzier curveT = smooth quadratic Belzier curvetoA = elliptical ArcZ = closepath注释:以上所有命令均允许小写字母。大写表示绝对定位,小写表示相对定位。
参考:http://www.w3school.com.cn/svg/svg_path.asp
来看看效果:
更多相关文章
- Android之布局属性重点
- Android(安卓)3D 游戏开发教程– Part I-VI
- Android_TextView属性XML详解
- Android(安卓)资源加载机制详解
- drawable属性
- android:ellipsize实现跑马灯效果总结
- Android抽象布局——include、merge 、ViewStub
- Android_TextView属性XML详解
- android activity ImageView全屏设置