I am trying to create a following shape in android.
I tried following code but it's only for changing the corners
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
<gradient
android:startColor="#00EBCF"
android:endColor="#00BEEC"
android:angle="180"
android:type="linear" />
<corners
android:bottomLeftRadius="80dp"
android:bottomRightRadius="80dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
What do I need to make changes in code to achieve the above shape?
Edit1
As per the answer I used following code (modifications in layout height):
<?xml version="1.0" encoding="utf-8"?>
</shape>
</item>
<item
android:width="1500dp"
android:height="200dp"
android:top="95dp">
<shape android:shape="oval">
<solid android:color="#36D6E9" />
</shape>
</item>
But when I am using this layout as a background for LinearLayout. It's showing me this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/header_shape_rect">
use this as an example
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:height="200dp">
<shape android:shape="rectangle">
<solid android:color="#ccc"/>
</shape>
</item>
<item android:height="200dp" android:top="95dp" android:width="1500dp" >
<shape android:shape="oval">
<solid android:color="#ccc"/>
</shape>
</item>
</layer-list>
Related
Here is the image which I want to design in android studio.
This will give you the same image that you're looking for.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="#color/black" />
<stroke
android:width="16dp"
android:color="#color/white" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<stroke
android:width="8dp"
android:color="#color/black" />
</shape>
</item>
</layer-list>
You can achieve the required output by using layer-list. In the drawable folder create a new Drawable Resource File named background.xml and replace with the following code in the file.
This is the code for background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="#5271ff" />
<stroke
android:width="20dp"
android:color="#f5fffe" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<stroke
android:width="10dp"
android:color="#4d75f9" />
</shape>
</item>
</layer-list>
Summarize the problem:
Hello, I want to create Seekbar like this one in the design:
So the thumb has something like padding/margin at left and right and bars are rounded on both sides.
What I've tried so far:
I've already tried to create thumb picture like this:
Unfortunately, it turned out that I can't use this picture because I need to change this black halo around green point programmatically.
That's why I've built seekbar completely in XML (no pngs images):
Seekbar:
<SeekBar
android:id="#+id/player_seekbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/SeekBarPlayer"
local:MvxBind="Max Duration; Progress SliderPosition, Mode=OneWay; SecondaryProgress Downloaded; Visibility(LivePlaybackToVisibility(CurrentTrack))"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView" />
SeekbarBackground:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners android:radius="5dp" />
<solid android:color="#3d4b58" />
</shape>
</item>
</layer-list>
SeekbarSecondaryProgress:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/progressshapesecondary" >
<clip>
<shape
android:shape="rectangle" >
<size android:height="5dp"/>
<corners
android:radius="5dp" />
<solid android:color="#8883e76b"/>
</shape>
</clip>
</item>
</layer-list>
SeekbarProgress:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/progressshape" >
<clip>
<shape
android:shape="rectangle" >
<size android:height="5dp"/>
<corners
android:radius="5dp" />
<solid android:color="#83e76b"/>
</shape>
</clip>
</item>
</layer-list>
And it provides me a seekbar like this:
Summarazing
How can I achieve the following seekbar design from now on?
Use below code for thumb drawable:
seekbar_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#8883e76b"/>
<stroke android:color="#color/black" android:width="3dp"/>
<size android:height="30dp" android:width="30dp"/>
</shape>
</item>
</selector>
Use below code for seekbar, just change color what you want:
<item android:id="#android:id/background">
<shape android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#color/fofo_grey" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#color/signup_green" />
<stroke
android:width="6dp"
android:color="#color/fofo_grey" />
</shape>
</clip>
</item>
I'm trying to create a drawable with two shapes next to each other using layer-list, how would I do it?
You can use the following code to have the drawable you want(Change the colors and height as you want)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="center">
<shape android:shape="rectangle">
<size
android:width="5dp"
android:height="5dp" />
<solid android:color="#color/colorAccent"/>
</shape>
</item>
<item android:gravity="right">
<shape android:shape="rectangle">
<size
android:width="1dp"
android:height="5dp" />
<solid android:color="#color/colorPrimary"/>
</shape>
</item>
</layer-list>
Hi guys so i created 2 xmls for 3 shapes. 2 shapes are rectangle 1 is ring.
First XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#color/colorGrey"/>
<size android:height="40dp" android:width="10dp"/>
</shape>
Second XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/colorWhite"/>
<size android:height="40dp" android:width="40dp"/>
</shape>
Then i created a layer-list drawable like this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="#drawable/rectangle"
android:gravity="center" />
</item>
<item android:top="40dp">
<bitmap android:src="#drawable/circle"
android:gravity="center" />
</item>
<item android:top="40dp">
<bitmap android:src="#drawable/rectangle"
android:gravity="center" />
</item>
</layer-list>
My main goal was to create this. Main problem is they are stacking top of each other.
Try this (I've assumed a 40x40dp image size based on your code and a white background based on your image):
<?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/white"/>
<size android:height="40dp" android:width="40dp"/>
</shape>
</item>
<item
android:right="18dp"
android:left="18dp">
<shape
android:shape="rectangle">
<solid android:color="#color/green"/>
<size android:height="40dp" android:width="4dp"/>
</shape>
</item>
<item android:gravity="center">
<shape
android:shape="oval">
<solid android:color="#color/green"/>
<size android:height="15dp" android:width="15dp"/>
<stroke android:width="2dp" android:color="#color/white"/>
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<solid android:color="#ffffff"/>
<stroke android:width="30dp"
android:color="#51000000"
/>
</shape>
It gives a "half-inner-half-outer" stroke.
What I need is outer semitransparent stroke only. Can it be done?
What I have is
What I need is
Thanks
you can check this shape created using layer list with it's items.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="oval" >
<solid android:color="#fff" />
</shape>
</item>
<item >
<shape android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke
android:width="50dp"
android:color="#30000000" />
</shape>
</item>
</layer-list>
if you add alpha for stroke color the inner half is without transparent and outer is transparent.this is how stroke color works.if you don't want inner circle use color without Alpha and adjust Hexcode.
Try adding android:innerRadius="0dp" for shape attribute -
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
>
<solid android:color="#ffffff"/>
<stroke android:width="4dp"
android:color="#51000000"
/>
</shape>
This is Android studio XML preview bug.look like The image you shown above from Android studio xml preview.actually there is no inner and outer layer.
I've found no way to do that other than the following:
<?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="#android:color/transparent" />
<stroke
android:width="#dimen/stroke_width"
android:color="#33000000" />
</shape>
</item>
<item >
<shape android:shape="oval" >
<solid android:color="#fff" />
<stroke
android:width="#dimen/stroke_width"
android:color="#android:color/transparent">
</stroke>
</shape>
</item>
</layer-list>
Try This: (Change dimens and colors to fit your needs)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="#dimen/default_stroke_size_small" android:color="#color/colorDimBlack"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke android:width="#dimen/default_stroke_size_small" android:color="#android:color/transparent"/>
<solid android:color="#color/colorWhite"/>
</shape>
</item>
</layer-list>
update your code to this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ffffff" />
<stroke
android:width="30dp"
android:color="#000000" /> <--- this line you have to change
</shape>
You are missing one f in your first color. Thus it's creating a half visible pattern
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<solid android:color="#fffffff"/>
<stroke android:width="30dp"
android:color="#51000000"
/>
</shape>