2

I am trying to find out how to use drawable xml (<shape>) to create a right angled triangle like below (but fill with color without the black line):

enter image description here

I try to think from the angle of halving a rectangle from diagonal line, but still...can't find how to achieve it.

Is it doable with Android drawable xml?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Leem.fin
  • 40,781
  • 83
  • 202
  • 354

1 Answers1

2

Here you go:

Create your xml file

<?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_main10"
    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:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ul_ts.emvsdktester.drawabletraining.Main10Activity">
    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/my_shape6"></LinearLayout>
</RelativeLayout>

Create my_shape6.xml inside the drawable 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">

    <path
        android:fillColor="#32c2b6"
        android:pathData="M0 20 L100 0 L100 20 Z"
        android:strokeColor="#9a1616" />

</vector>

The result

enter image description here

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