Android - How to draw a transparent rectangle bordered shape with only its corners visible?


I want to draw a shape like this in android.

enter image description here

I used the following code

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/shape_my">
<stroke
    android:width="2dp"
    android:dashWidth="20dp"
    android:dashGap="20dp"
    android:color="#c1c1c1" />
<padding
    android:bottom="20dp"
    android:left="20dp"
    android:right="20dp"
    android:top="20dp" />
<corners android:radius="0dp" />
<solid android:color="#00000000" />
</shape>

But no perfection I got. Help me, friends.


Answers:


Try this ,it worked perfect for me

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item
      android:width="300dp"
      android:height="300dp">
    <shape android:shape="rectangle">
        <stroke
            android:width="15px"
            android:color="#00000000" />

        <solid android:color="#00000000" />

    </shape>
</item>
<item
    android:width="7dp"
    android:bottom="0dp"
    android:top="260dp">
    <shape android:shape="rectangle">
        <solid android:color="#000" />
    </shape>
</item>
<item
    android:width="7dp"
    android:bottom="260dp"
    android:top="0dp">
    <shape android:shape="rectangle">
        <solid android:color="#000" />
    </shape>
</item>
<item
    android:width="8dp"
    android:bottom="0dp"
    android:gravity="right"
    android:top="260dp">
    <shape android:shape="rectangle">
        <solid android:color="#000" />
    </shape>
</item>
<item
    android:width="8dp"
    android:bottom="260dp"
    android:gravity="right"
    android:top="0dp">
    <shape android:shape="rectangle">
        <solid android:color="#000" />
    </shape>
</item>
<item
    android:height="8dp"
    android:gravity="top"
    android:left="0dp"
    android:right="260dp"
    android:top="-1dp">
    <shape android:shape="rectangle">
        <solid android:color="#000" />
    </shape>
</item>
<item
    android:height="8dp"
    android:gravity="top"
    android:left="260dp"
    android:right="0dp"
    android:top="-1dp">
    <shape android:shape="rectangle">
        <solid android:color="#000" />
    </shape>
</item>
<item
    android:height="8dp"
    android:gravity="bottom"
    android:left="0dp"
    android:right="260dp">
    <shape android:shape="rectangle">
        <solid android:color="#000" />
    </shape>
</item>
<item
    android:height="8dp"
    android:gravity="bottom"
    android:left="260dp"
    android:right="0dp">
    <shape android:shape="rectangle">
        <solid android:color="#000" />
    </shape>
</item>