如何在可绘制对象中创建带有笔触的一个三角形边的矩形形状?

时间:2019-03-14 07:57:08

标签: android

有没有办法在Android XML中的矩形中绘制一个单边三角形。就像下面的这张图片...

Please check this image

3 个答案:

答案 0 :(得分:0)

您可以像这样使用vector drawable

    <?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportWidth="200"
android:viewportHeight="200">

<path
    android:fillColor="#ffffff"
    android:pathData="M7.5 131.61L138.5 128.88L187.87 97.48L138.5 67.2L7.5 67.2L7.5 131.61Z" />
<path
    android:fillColor="#000000"
    android:fillAlpha="0"
    android:strokeColor="#152dbe"
    android:strokeWidth="3"
    android:pathData="M7.5 131.61L138.5 128.88L187.87 97.48L138.5 67.2L7.5 67.2L7.5 131.61Z" />

答案 1 :(得分:0)

为此,您可以使用向量

<vector android:height="24dp"
    android:viewportHeight="24.0" android:viewportWidth="24.0"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">

    <path android:fillColor="@color/white" android:pathData="M0,0 H17 L23 5 L17 10 H0 V0 "
        android:strokeColor="@color/color_blue"
        android:strokeWidth="1"/>
</vector>

答案 2 :(得分:0)

仅供参考。

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="1365dp"
        android:height="1024dp"
        android:viewportHeight="1024"
        android:viewportWidth="1365">

    <path
        android:fillColor="#1296db"
        android:pathData="M1236.4080406 442.12695338l-164.79492238-263.67187551A131.83593775 131.83593775 0 0 0 959.88216119 116.4921875H333.66145857a131.83593775 131.83593775 0 0 0-131.83593775 131.83593775v527.3437495a131.83593775 131.83593775 0 0 0 131.83593775 131.83593775h626.22070262a131.83593775 131.83593775 0 0 0 111.73095703-61.96289037l164.79492238-263.67187551a131.83593775 131.83593775 0 0 0 0-139.74609324z m-56.03027394 104.80957031l-164.79492162 263.67187475A65.9179685 65.9179685 0 0 1 959.88216119 841.589844H333.66145857a65.9179685 65.9179685 0 0 1-65.91796925-65.91796925V248.32812525a65.9179685 65.9179685 0 0 1 65.91796925-65.91796925h626.22070262a65.9179685 65.9179685 0 0 1 56.03027395 30.98144556l164.79492162 263.67187475a65.9179685 65.9179685 0 0 1 0 69.87304738z"/>
</vector>