I've been trying to recreate a background image in xml (as drawable). Since the background is a simple shape, it would be better if it is created as xml drawable.
The is a really large gradient circle that squares off at the left, top and right border.
What I've tried
<?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:height="20dp" />
<gradient
android:type="linear"
android:startColor="#color/gradientLeft"
android:centerColor="#color/gradientMiddle"
android:endColor="#color/gradientRight"
android:angle="0" />
</shape>
</item>
<item>
<shape
android:shape="oval">
<padding
android:top="20dp" />
<gradient
android:type="linear"
android:startColor="#color/gradientLeft"
android:centerColor="#color/gradientMiddle"
android:endColor="#color/gradientRight"
android:angle="0" />
</shape>
</item>
</layer-list>
I've tried to create a layer-list. This layer list contains 2 shapes, a rectangle and an oval.
The rectangle has a gradient and a height of 20dp (to test).
The oval also has the same gradient, and has a top padding of 20dp.
This however, doesn't create a circular shape, but fills the whole shape with the gradient. Can someone help me?
Try this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" />
</item>
<item
android:bottom="300dp"
android:left="-100dp"
android:right="-100dp"
android:top="-80dp">
<shape android:shape="oval">
<size android:height="20dp" />
<gradient
android:angle="0"
android:centerColor="#color/colorAccent"
android:endColor="#color/red"
android:startColor="#color/colorPrimary"
android:type="linear" />
</shape>
</item>
</layer-list>
OUTPUT
Try this
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item>
<shape android:shape="rectangle" >
<solid android:color="#ffffff"/>
</shape>
</item> <item
android:bottom="400dp"
android:left="-200dp"
android:right="-200dp"
android:top="-100dp">
<shape android:shape="oval">
<size android:height="20dp" />
<gradient
android:type="linear"
android:startColor="#FD4F33"
android:centerColor="#EE3A53"
android:endColor="#DF2772"
android:angle="0" />
</shape> </item> </layer-list>
The background will be like this
Related
I want to give shadow inside a cardview and got solution like shown below :
but I also want to give radius to shadow as well which I'm not able to do,
Here's my code for the same :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/yellow"/>
<corners android:radius="#dimen/_20sdp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="180"
android:centerColor="#00FF0000"
android:centerX="0.97"
android:centerY="0.5"
android:endColor="#5C000000"
android:startColor="#00FF0000" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:centerColor="#00FF0000"
android:centerY="0.1"
android:endColor="#00FF0000"
android:startColor="#6B000000" />
<corners android:radius="#dimen/_20sdp" />
</shape>
</item>
</layer-list>
Can anyone help me with this?
Thanks in advance.
Take transfers image like a shadow you want the top layout.
or
create gradient drawable.
Try something like below
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:angle="90"
android:centerColor="#555994"
android:endColor="#b5b6d2"
android:startColor="#555994"
android:type="linear" />
<corners
android:radius="0dp"/>
</shape>
I am trying to create a drawable, where I have 3 circles (on top of each other) on a linear gradient and the circles are shifted 50% to the left.
This is my attempt so far:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#4833A6"
android:endColor="#1E479C"
android:type="linear"
/>
</shape>
</item>
<item android:left="-115dp">
<shape android:shape="oval">
<size android:width="230dp" android:height="233dp"/>
<solid android:color="#1AFFFFFF"/>
</shape>
</item>
<item android:left="-83dp">
<shape android:shape="oval">
<size android:width="166dp" android:height="166dp"/>
<solid android:color="#1AFFFFFF"/>
</shape>
</item>
<item android:left="-57.5dp">
<shape android:shape="oval">
<size android:width="115dp" android:height="115dp"/>
<solid android:color="#1AFFFFFF"/>
</shape>
</item>
</layer-list>
The desired effect:
What I have so far :(
What am I doing wrong?
Try to put in your item, the following:
<item
android:width="115dp"
android:height="115dp"
android:gravity="center|left"
android:left="-57dp">
<shape android:shape="oval">
<solid android:color="#1AFFFFFF"/>
</shape>
</item>
Don't define the size inside the shape, but inside the item itself. I tried here, and it's working properly.
Hi I am trying to gradient in android.
I am trying the following code
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#EF5350"
android:centerColor="#FFEBEE"
android:endColor="#EF5350"
android:angle="-270" />
</shape>
Result:
I want to increase the size of white in center. Please help me to solve my issue.
Try this :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="50dp">
<shape android:shape="rectangle">
<gradient
android:startColor="#EF5350"
android:endColor="#EF5350"
android:centerColor="#FFFFFF"
android:angle="270"/>
<size
android:height="100dp"
android:width="80dp"/>
</shape>
</item>
<item
android:bottom="50dp">
<shape android:shape="rectangle">
<gradient
android:startColor="#EF5350"
android:endColor="#FFFFFF"
android:centerColor="#FFFFFF"
android:angle="270"
/>
<size
android:height="100dp"
android:width="80dp"/>
</shape>
</item>
</layer-list>
You need to specify type inside the gradient tag,
For e.g. in my case I have defined radial for center gradient effect,
android:type="radial"
I have created gradient shape (centergradietbg.xml) with center gradient effect, look it my code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:centerColor="#c1c1c1"
android:endColor="#4f4f4f"
android:gradientRadius="400"
android:startColor="#c1c1c1"
android:type="radial" >
</gradient>
</shape>
Use this xml in your layout background using
android:background="#drawable/centergradietbg"
I want to set up circle size, but I don't want resize other elements in layer list.
I have this code:
<?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/drawer_color" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:endColor="#1b2727"
android:centerColor="#1a2a29"
android:startColor="#154440"
android:type="linear"
android:angle="90"/>
<size
android:height="600dp"
android:width="600dp" />
<stroke
android:width="3dip"
android:color="#color/drawer_ring_color" />
</shape>
</item>
</layer-list>
What I found:
And what I want to see:
How to do that?
Thanks!
Unfortunately this do not works this way, your drawable will take the size of view where you use that drawable.
Try to set padding in your code.
<item>
<shape android:shape="rectangle">
<solid android:color="#color/drawer_color" />
<padding
android:left="10dp"
android:top="100dp"
android:right="10dp"
android:bottom="100dp" />
</shape>
</item>
I want to make a rectange object (shape) with gradient and below it image background. I've got:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<gradient
android:type="linear"
android:startColor="#BF0e2634"
android:endColor="#BF0e2634"
android:angle="270"/>
<stroke
android:width="1dp"
android:color="#0e2634" >
</stroke>
<size
android:width="15dp"
android:height="15dp"/>
<corners android:topLeftRadius="3dp" android:topRightRadius="3dp"
android:bottomLeftRadius="3dp" android:bottomRightRadius="3dp"/>
</shape></item>
<item
android:drawable="#drawable/galaxy"
android:alpha="0.2"
/>
</layer-list>
But the image is overide the rectange with stroke and gradient. Please help me guys!