4

I'm trying to figure out how to create this background in xml, couldn't find anything that helped me.

background

Ignore the circle image of the kid and the text of course, I am talking about the background itself, is there a way to create something like that in xml?

Thanks in advance for any help. cheers!

Community
  • 1
  • 1
JozeRi
  • 3,219
  • 6
  • 27
  • 45

1 Answers1

0

I'm guessing you moved on, but you can do this using Vector Drawables.

The following is not accurate (the line is not completely straight), but should give you a good start:

New XML file:

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

    <path
        android:name="dark_triangle"
        android:fillColor="@color/blue"
        android:pathData="M 0,100 L 0,80 60,70 100,80 100,100 z" />

    <path
        android:name="light_triangle"
        android:fillColor="@color/color_light_blue"
        android:pathData="M 60,70 L 100,65 100,80 z" />

</vector>

In your layout:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitCenter"
    app:srcCompat="@drawable/test"
    />

You might need to add this to your layout as well:

    xmlns:app="http://schemas.android.com/apk/res-auto"

Notes:

MikeL
  • 2,756
  • 2
  • 23
  • 41