Rounded Inner Corners With Transparent Inside Frame
I am trying to make a frame from code so that I can apply it to make rounded inner corners with a solid fill outside and transparent inside. Just like a solid rectangle with transp
Solution 1:
create the following rounded_corner.xml:
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:bottom="-10dp"android:left="-10dp"android:right="-10dp"android:top="-10dp"><shapeandroid:shape="rectangle"><strokeandroid:width="10dp"android:color="#ffffff" /><cornersandroid:radius="20dp" /></shape></item></layer-list>
add this below your imageView, which you want to apply the frame on it:
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/my_image_view"
android:layout_alignLeft="@id/my_image_view"
android:layout_alignRight="@+id/my_image_view"
android:layout_alignTop="@id/my_image_view"
android:background="@drawable/rounded_corner" />
Solution 2:
First of all, create 3 xml
layout
in drawable folder:
- First: frame.xml
- Second: frame_build.xml
- Third: red.xml
(You can change this name as you wish),
frame.xml:
<?xml version="1.0" encoding="UTF-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:bottom="20dp"android:drawable="@drawable/red"android:top="-25dp" /><itemandroid:bottom="15dp"android:drawable="@drawable/frame_build"android:top="5dp"android:left="-5dp"android:right="-5dp" /></layer-list>
frame_build.xml :
<?xml version="1.0" encoding="UTF-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><paddingandroid:left="10dp"android:top="10dp"android:right="10dp"android:bottom="10dp" /><cornersandroid:radius="40dp" /></shape>
red.xml
<?xml version="1.0" encoding="UTF-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><strokeandroid:width="40dp"android:height="40dp"android:color="#B22222" /><paddingandroid:left="8dp"android:top="-1dp"android:right="8dp"android:bottom="9dp" /><cornersandroid:radius="-10dp" /></shape>
Finally refer your view or layout to Frame XML as follow :
android:background="@drawable/frame"
This tested and output as below image:
Hope this help .
Solution 3:
tweaking @Nima K solution, to avoid using an extra View
create frame.xml @ drawable
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:bottom="-10dp"android:left="-10dp"android:right="-10dp"android:top="-10dp"><shapeandroid:shape="rectangle"><strokeandroid:width="20dp"android:color="@color/frame_color" /><cornersandroid:radius="30dp" /></shape></item><item><shapeandroid:shape="rectangle"><solidandroid:color="@android:color/transparent" /><strokeandroid:width="20dp"android:color="@color/frame_color" /><cornersandroid:radius="40dp" /></shape></item></layer-list>
Then use it with 'android:background' attribute of your view
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/frame" />
Solution 4:
Maybe more simply;
<insetxmlns:android="http://schemas.android.com/apk/res/android"android:inset="-6dp"><shapeandroid:shape="rectangle"><solidandroid:color="#FFFFFF" /><strokeandroid:width="12dp"android:color="#000000" /><cornersandroid:radius="16dp" /></shape></inset>
Post a Comment for "Rounded Inner Corners With Transparent Inside Frame"