1

I want create shape such as this image :
enter image description here

But i do not want use 9 pach png image, i want create this shape in drawable folder.
How can i create this? Any help could be appreciated! Thanks

Jhaman Das
  • 1,094
  • 13
  • 28
F_Feed
  • 125
  • 1
  • 1
  • 8
  • You need at least one 9 patch for the triangle. Otherwise, it's 2 rectangles – OneCricketeer Apr 25 '16 at 13:16
  • @cricket_007, yes it's 2 rectangles, but i do not want use 9 patch image. i want create this with shape – F_Feed Apr 25 '16 at 13:20
  • It may be worth looking at this post: http://stackoverflow.com/questions/2517589/making-a-triangle-shape-using-xml-definitions – OneCricketeer Apr 25 '16 at 13:24
  • @cricket_007, thank you man, i create this in drawable and with XML. after create this i send code in this topic. thanks for your help – F_Feed Apr 25 '16 at 13:28

1 Answers1

0

Create your 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_main7"
    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.Main7Activity">


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/my_shape4"></LinearLayout>

</RelativeLayout>

Create my_shape4.xml in your drawable file

<?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 20 L50 20 L60 0 L100 0"
            android:strokeColor="#000000"
            android:strokeWidth="4" />
        <path
            android:fillColor="#42ce3b"
            android:pathData="M100 0 L100 50 L0 50 L0 20 L50 20 L60 2 L100 2"
            android:strokeWidth="0" />
    </group>
</vector>

The results

enter image description here

William Kinaan
  • 28,059
  • 20
  • 85
  • 118
  • can you please explain , how you created my_shape4.xml – Umar Ata Dec 30 '16 at 09:05
  • @UmarAta create an example file named my_shape4.xml inside your drawable folder and copy the copy I've posted in the answer. easy !! – William Kinaan Dec 30 '16 at 09:21
  • that's not what I asked, I simply mean to ask that how you coded the vector drawable for this shape is there any tutorial or link for decumentation? – Umar Ata Dec 30 '16 at 09:27
  • @UmarAta you can ready more about vectors in [this link](https://developer.android.com/training/material/drawables.html) – William Kinaan Dec 30 '16 at 09:29