1

edited part of the question I want to draw a trapezium shape to apply for a Linear-layout. so far I've done following. But I want to only to appear the trapezium. other parts must be not visible. thank you. i dont want the othe parts except trapezuim

William Kinaan
  • 28,059
  • 20
  • 85
  • 118
Neshan Manilka
  • 64
  • 1
  • 2
  • 10
  • This post helped me a lot in creating a trapezium view https://arkapp.medium.com/trapezium-view-for-android-584799c7e849 With the help of this I was able to create a custom view with one edge as a slope. – abdul rehman Nov 29 '20 at 09:53

1 Answers1

1

Here you go:

Create an layout

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

Notice that the layout has a drawable background which is: myshape.xml

myshape.xml

Create myshape.xml file in the drawbable folder:

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

Result

enter image description here

After your edit

Change myshape.xml to:

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

The result

enter image description here

William Kinaan
  • 28,059
  • 20
  • 85
  • 118