Shape Corners With Negative Radius In Android
Solution 1:
If someone have the same problem, best way is use 9.png drawables. In xml it's not possible.
Solution 2:
You can achieve that with using <vector
in a custom drawable
file, here invert_shape.xml
:
<vectorxmlns:android="http://schemas.android.com/apk/res/android"android:width="200dp"android:height="200dp"android:viewportWidth="400"android:viewportHeight="400"><pathandroid:pathData="M3.146,256.500 L3.146,73.449 C41.770,72.388 72.757,41.041 72.757,2.500 L271.500,2.500 L271.500,256.500 L3.146,256.500 Z"android:fillColor="#eeffcc"android:strokeColor="#000000"android:strokeWidth="5"/></vector>
After that you need to set this drawable
as android:background
of your LinearLayout
in your activity_main.xml
like this:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/linear_layout"
android:background="@drawable/invert_shape"
android:layout_centerInParent="true"
android:orientation="horizontal" />
The result:
You may asked yourself how to achieve the android:path
in your <vector
, I used a simple solution for that. You can use programs like Photoshop
or Illustrator
and create your shape there in a layer
. If you have done that, right click on your layer
and select "Copy SVG
". Now you copied the shape, paste it in your drawable
(here invert_shape.xml
) in Android Studio
and you will get parameters like android:path
and android:stroke
of your photoshop shape. Get rid of the unnecessary paramteres and make sure you use the right attributes in the XML
itself. Now, there's no end for your creativity. Cheers! :)
Solution 3:
You can able to give the OneSide Corner with set the below frame as background to the layout.
<?xml version="1.0" encoding="UTF-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><strokeandroid:width="1dip"
/><solidandroid:color="#3D2A1D"/><cornersandroid:radius="20sp"android:topRightRadius="0dp"android:bottomLeftRadius="0dp"android:bottomRightRadius="0dp"/></shape>
I am not sure with the -ve border radios.
Post a Comment for "Shape Corners With Negative Radius In Android"