三角形作为一个基本的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>

其中viewportWidthviewportHeight属性用于申明坐标的大小,widthheight属性标书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 svg 绘制三角形_第1张图片

更多相关文章

  1. drawable属性
  2. android开发笔记1:TextView的属性详解
  3. TextView支持的XML属性及相关方法
  4. Android 属性动画(Property Animation) 完全解析
  5. android 动画Animation属性大全(-)
  6. Android adb(Android Debug Bridge)常用命令
  7. Android矢量图(二)--VectorDrawable所有属性全解析

随机推荐

  1. Android(安卓)绘制电池电量图标(含充电状
  2. Android:windowSoftInputMode属性说明
  3. Android(安卓)- 基于Toolbar的Navigation
  4. android to unzip zip files
  5. Android 四大组件的工作过程(Android开发
  6. Android(安卓)apktool反编译资源文件为空
  7. android studio开发环境配置(指定SDK及卸
  8. android 通过intent调用短消息的正确方法
  9. 新技能get:在任意目录执行NDK编译
  10. android meta-data 读取