Android svg 绘制三角形
16lz
2021-01-23
三角形作为一个基本的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
来看看效果:
更多相关文章
- drawable属性
- android开发笔记1:TextView的属性详解
- TextView支持的XML属性及相关方法
- Android 属性动画(Property Animation) 完全解析
- android 动画Animation属性大全(-)
- Android adb(Android Debug Bridge)常用命令
- Android矢量图(二)--VectorDrawable所有属性全解析