如何绘制 android 形状的梯形?

how to draw a trapezium for android shape?

edited part of the question我想画一个梯形来申请线性布局。到目前为止,我已经完成了以下工作。但我只想出现梯形。其他部分必须不可见。谢谢你。 i dont want the othe parts except trapezuim

给你:

创建布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:background="@drawable/myshape"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.williamkinaan.expresso.Main2Activity">

</RelativeLayout>

请注意布局有一个可绘制的背景,它是:myshape.xml

myshape.xml

在 drawbable 文件夹中创建 myshape.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="100dp" android:height="100dp" android:viewportHeight="100" android:viewportWidth="100">
    <group>
        <path android:pathData="M0 0 L100 0 L100 50 L75 100 L 25 100 L 0 50 Z"
            android:strokeColor="#7e0b0b"
            android:strokeWidth="2"/>
        <path android:pathData="M100 0 L50 80 L0 0" android:strokeColor="#7e0b0b"
            android:strokeWidth="2"/>
        <path android:strokeColor="#7e0b0b" android:strokeWidth="2" android:pathData="M80 30 L20 30"/>
        <path android:strokeColor="#7e0b0b" android:strokeWidth="2" android:pathData="M50 80 L63 100" />
    </group>
</vector>

结果

编辑后

将myshape.xml更改为:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="100dp"
    android:height="100dp"
    android:viewportHeight="100"
    android:viewportWidth="100">
    <path
        android:pathData="M0 0 L100 0 L75 40 L25 40 Z"
        android:strokeColor="#7e0b0b"
        android:strokeWidth="2" />

</vector>

结果