[英]What is path data of android drawable mean
我有一個看法:
<ImageView
android:id="@+id/imageView2"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/sel_to_arrow" />
sel_to_arrow.xml
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="100dp"
android:width="100dp"
android:viewportHeight="100"
android:viewportWidth="100">
<path
android:name="light_triangle"
android:fillColor="#93186C"
android:pathData="M 0,0 L 100,0 0,100 z" />
</vector>
什么是路徑數據: M 0,0 L 100,0 0,100 z
均值
其中 position 是top left
top right
bottom left
bottom right
M 或 m (X,Y)
moveto:將cursor移動到position,大寫是絕對的,小寫是相對的
L 或 l (X,Y)
lineto:從當前的 position 到 X,Y 指定的 position 繪制一條線
H 或 h (X)
Horizontal lineto 從當前的 cursor position 到 X 指定的 position 繪制一條水平線。
V 或 v (Y)
Vertical lineto 繪制一條從當前 cursor position 到 Y 指定的 position 的垂直線。
Z 或 z
closepath:從cursor的當前position到路徑的開始position畫一條線。
對於上述所有參數,大寫表示絕對 position,小寫表示相對 position。
視口高度和寬度為 100,因此您的邊界如下
1.left - 0
2.right - 100
3.top - 0
4.bottom - 100
因此,您必須根據這些值創建與Canvas
類的 drawPath drawPath()
方法相同的路徑。
//draw rectangle
Path path=new Path();
path.moveTo(0,0);
path.lineTo(100,0);
path.lineTo(0,100);
path.lineTo(100,0);
path.close();
canvas.drawPath(path,mDrawPaint);
這將轉換為
android:pathData="M 0,0 L 100,0 L 0,100 L 100,0 z"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.