如何绘制android形状的梯形?

时间:2016-12-22 04:29:08

标签: android android-drawable shape android-shape

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

1 个答案:

答案 0 :(得分:1)

你走了:

创建布局

<?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>

结果

enter image description here

编辑后

将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>

结果

enter image description here