In my android app, I need border only on four corners as shown in fig (white colored).
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="6">
<VideoView
android:id="@+id/video1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<View
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:background="@drawable/cornerbg" />
</RelativeLayout>
cornerbg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/transparent" />
<stroke
android:width="1dp"
android:color="@color/btn_border"
android:dashWidth="50dp" // I tried this but not getting expected
android:dashGap="60dp"/>
</shape>
</item>
</layer-list>
How can I write xml for this?
Please help, Thanks
Below is the drawable that doesn't depends on the width and height of the rectangle, you can use this drawable for portrait and landscape. Please adjust the width and height of the border :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="8dp"
android:height="48dp"
android:gravity="top|left">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="48dp"
android:height="8dp"
android:gravity="top|left">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="8dp"
android:height="48dp"
android:gravity="top|right">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="48dp"
android:height="8dp"
android:gravity="top|right">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="8dp"
android:height="48dp"
android:gravity="bottom|left">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="48dp"
android:height="8dp"
android:gravity="bottom|left">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="8dp"
android:height="48dp"
android:gravity="bottom|right">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="48dp"
android:height="8dp"
android:gravity="bottom|right">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
I know it's a question of a long time ago, but I had the same problem.
I solved by creating secondary layout and including in my main layout.
I hope this solution can help somebody.
main_layout.xml
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="6">
<VideoView
android:id="@+id/video1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<include layout="@layout/camera_box_layout" />
</RelativeLayout>
camera_box_layout.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="40dp"
android:background="@android:color/transparent">
<!-- Top horizzontal lines -->
<View
android:layout_width="100dp"
android:layout_height="2dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:background="@android:color/darker_gray" />
<View
android:layout_width="100dp"
android:layout_height="2dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:background="@android:color/darker_gray" />
<!-- Top vertical lines -->
<View
android:layout_width="2dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:background="@android:color/darker_gray" />
<View
android:layout_width="2dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:background="@android:color/darker_gray" />
<!-- Bottom horizzontal lines -->
<View
android:layout_width="100dp"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@android:color/darker_gray" />
<View
android:layout_width="100dp"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="@android:color/darker_gray" />
<!-- Bottom vertical lines -->
<View
android:layout_width="2dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@android:color/darker_gray" />
<View
android:layout_width="2dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="@android:color/darker_gray" />
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With