I'm trying to achieve this effect, but I can't make the white circular stroke inside the circle. In my implementation, the white stroke appears outside the circle
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dip" />
<stroke
android:width="5dip"
android:color="#ffffff" />
<solid android:color="#f50000" />
</shape>
</item>
</layer-list>
Expected output:-
I accomplished this using a <layer-list> and an <inset> oval shape:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#f50000"/>
</shape>
</item>
<item>
<inset
android:insetTop="5dp"
android:insetLeft="5dp"
android:insetRight="5dp"
android:insetBottom="5dp">
<shape android:shape="oval">
<stroke
android:color="#fff"
android:width="5dp"/>
</shape>
</inset>
</item>
</layer-list>
You can control the inset amount and the stroke width by changing the values in the second item
here you go. Just modify a little your file to have two items and add a padding on the second.
I hope it helps:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="oval">
<solid android:color="#f50000" />
</shape>
</item>
<item
android:left="2dp"
android:right="2dp"
android:top="2dp"
android:bottom="2dp">
<shape
android:shape="oval">
<stroke
android:width="2dp"
android:color="#ffffff" />
</shape>
</item>
</layer-list>
You need an xml like this (optimized):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="oval">
<solid android:color="#007" />
</shape>
</item>
<item
android:left="2dp"
android:right="2dp"
android:top="2dp"
android:bottom="2dp">
<shape
android:shape="oval">
<stroke
android:width="1dp"
android:color="#f00" />
<size
android:width="25dp"
android:height="25dp" />
</shape>
</item>
</layer-list>
or xml like this (not optimized):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#007" />
<size
android:width="25dp"
android:height="25dp" />
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke
android:width="8dp"
android:color="#android:color/transparent" />
<solid android:color="#f00" />
<size
android:width="45dp"
android:height="45dp" />
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke
android:width="10dp"
android:color="#android:color/transparent" />
<solid android:color="#007" />
<size
android:width="10dp"
android:height="10dp" />
</shape>
</item>
</layer-list>
for this result:
Related
I have a drawable which is a circle with a stroke. How do I add a margin to that stroke?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#color/black" />
<stroke
android:width="3dp"
android:color="#android:color/red" />
</shape>
</item>
</layer-list>
This is what I want:
I've tried adding another <item> with a stroke but that doesn't work
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<stroke
android:width="3dp"
android:color="#android:color/blue" />
</item>
<item>
<shape android:shape="oval">
<solid android:color="#color/black" />
<stroke
android:width="3dp"
android:color="#android:color/red" />
</shape>
</item>
</layer-list>
Also tried adding it in the same <shape/> tag
<item>
<shape android:shape="oval">
<solid android:color="#color/black" />
<stroke
android:width="3dp"
android:color="#android:color/blue" />
<stroke
android:width="3dp"
android:color="#android:color/red" />
</shape>
</item>
I've also tried adding dp to the <item> tag
<item
android:left="6dp"
android:top="6dp"
android:bottom="6dp"
android:right="6dp">
but that only creates margin from the viewport to the drawable
Could someone help me please?
Try this :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#color/black" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="oval">
<stroke
android:width="10dp"
android:color="#android:color/red" />
</shape>
</item>
</layer-list>
For the second one :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient
android:endColor="#android:color/transparent"
android:gradientRadius="20"
android:startColor="#android:color/transparent" />
<stroke
android:width="8dp"
android:color="#android:color/red" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="oval">
<gradient
android:endColor="#android:color/black"
android:gradientRadius="20"
android:startColor="#android:color/black" />
<stroke
android:width="8dp"
android:color="#android:color/transparent" />
</shape>
</item>
</layer-list>
How would I use a stroke on only the right side of my drawable WITHOUT using insets?
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="20dp"/>
<solid android:color="#color/colorWhite" />
<stroke
android:width="1dp"
android:color="#color/colorPink">
</stroke>
</shape>
</item>
</layer-list>
Edit: Cannot use negative insets because of overlap issue
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#ff0000" />
</shape>
</item>
<item android:right="2dp">
<shape>
<solid android:color="#android:color/white" />
</shape>
</item>
</layer-list>
or use padding:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#ff0000" />
<padding android:right="1dp"/>
</shape>
</item>
<item>
<shape>
<solid android:color="#android:color/white" />
</shape>
</item>
</layer-list>
or:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#ffffff"/>
</shape>
</item>
<item android:gravity="right">
<shape>
<size android:width="1dp"/>
<solid android:color="#ff0000"/>
</shape>
</item>
</layer-list>
or:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="-2dp"
android:left="-2dp"
android:top="-2dp">
<shape>
<solid android:color="#android:color/white" />
<stroke
android:width="1dp"
android:color="#ff0000" />
</shape>
</item>
</layer-list>
You can achieve that by drawing a pink layer and then, drawing a white layer 1dp distant from the right border:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Pink layer -->
<item android:width="20dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorWhite" />
</shape>
</item>
<!-- white layer. It'll cover the pink layer except the last dp -->
<item android:right="1dp" android:width="19dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorWhite" />
</shape>
</item>
</layer-list>
Maybe, you can adjust
I would like to create the following background with a layer-list:
So basically a circle which has an outer stroke border.
I created the following XML:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#fff"/>
<size
android:width="10dp"
android:height="10dp"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke android:color="#ff" android:width="2dp"/>
<size
android:width="25dp"
android:height="25dp"/>
</shape>
</item>
</layer-list>
But this shows only one solid oval. Any help is appreciated!
Try This Change Color as per your requirement
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="60dp"
android:height="60dp"
android:top="15dp"
android:right="15dp"
android:bottom="15dp"
android:left="15dp">
<shape
android:shape="oval">
<solid android:color="#ffffff" />
</shape>
</item>
<item>
<shape
android:shape="oval">
<stroke android:width="8dp"
android:color="#ffffff"/>
</shape>
</item>
</layer-list>
Try this .xml File
Tried to edit also you want to Exact
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:topLeftRadius="20dp"
android:topRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
/>
<solid
android:color="#"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="100dp"
android:height="100dp"
/>
<stroke
android:width="3dp"
android:color="#33779C"
/>
android:shape="oval">>
<solid android:color="#FFFFFF" />
<size android:height="25dp"
android:width="25dp"/>
</shape>
The Result shape Like This...
I am trying to create a shape drawable like below.
where only the top left section is in different color ( here white ). Thought placing a rectangle with smaller size would let me achieve this but I was wrong. Am I even going in the right direction?
Here's my drawable.xml file.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size android:width="15dp" android:height="15dp"/>
<solid android:color="#android:color/white" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#android:color/black" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size android:width="60dp" android:height="60dp"/>
<solid android:color="#android:color/white" />
</shape>
</item>
<item android:left="40dp">
<shape android:shape="rectangle">
<size android:width="30dp" android:height="30dp"/>
<solid android:color="#ff0000" />
</shape>
</item>
<item android:top="30dp" android:bottom="0dip">
<shape android:shape="rectangle">
<size android:width="10dp" android:height="10dp"/>
<solid android:color="#ff0000" />
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke android:color="#android:color/black" android:width="1dp"/>
<size android:width="60dp" android:height="60dp"/>
<solid android:color="#ff0000" />
</shape>
</item>
</layer-list>
I am trying to figure out how I would stack shapes so I can create the following ribbon(Pink/White/Pink/White/Pink part). I will then be using this as a background for my textview.
I figured it out using a layer-list
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFe5887c" />
<size android:width="2dp" android:height="2dp"/>
</shape>
</item>
<item android:top="2dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFFFF" />
<size android:width="1dp" android:height="1dp"/>
</shape>
</item>
<item android:top="3dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFe5887c" />
<size android:width="20dp" android:height="20dp"/>
</shape>
</item>
<item android:top="23dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFFFF" />
<size android:width="1dp" android:height="1dp"/>
</shape>
</item>
<item android:top="24dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFe5887c" />
<size android:width="2dp" android:height="2dp"/>
</shape>
</item>
</layer-list>