Android : How to create oval size drawable resouce? - android

I am trying to create drawable resource oval com rectangle shape? I want exact the below shape
But I am getting the follow :
what I'm using:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="#36D53D"
android:centerColor="#36D53D"
android:endColor="#36D53D"
android:angle="90"/>
<padding android:left="3dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
<corners android:radius="160dp"></corners>
</shape>
how to create the shape what I want? Thank you in advance

Try this one for oval.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<!-- fill/color -->
<solid
android:color="#ff0000"/>
<!-- Control the width and height of the shape -->
<size
android:width="120dp"
android:height="70dp"/>
</shape>
Rectangle with rounded corner
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- fill/color -->
<solid
android:color="#ff0000"/>
<!-- Control the width and height of the shape -->
<size
android:width="200dp"
android:height="70dp"/>
<!-- Control the radius of each corners -->
<corners
android:topLeftRadius="30dp"
android:topRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"/>
</shape>

Try this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#189B5F" />
<corners
android:topLeftRadius="15dp"
android:topRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
/>
</shape>

use shape drawable and for android:shape give rectangle
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
</shape>
increase the corner dp value can keep checking. i think giving around 20-25dp for all corners will give you that shape. And for correction it is not oval it is rounded rectangle.

Related

Rectangle in xml without bottom side

I have a shape rectangle in my drawable like this
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
<stroke
android:width="1dp"
android:color="#android:color/white"
/>
</shape>
How, can I hide bottom line ?
<?xml version="1.0" encoding="UTF-8"?>
<!-- inset is used to remove border from top, it can remove border from any other side-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetTop="-2dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/rectangle">
<stroke android:width="1dp" android:color="#b7b7b7" />
<corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp"/>
<solid android:color="#454444"/>
</shape>
</inset>
use this code
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the line -->
<item>
<shape>
<solid android:color="#yourColor"
/>
</shape>
</item>
<!-- This is full view -->
<item android:bottom="10dp">
<shape>
<solid android:color="#backGroundColor" />
</shape>
</item>
this will add a 10dp height line at bottom of your view , u can change size of the line with
<item android:bottom="10dp">
and change color too
good luck

Semi transparent image background in Android shape xml

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!

Add gradient in edit text border in android

I want to add gradient only to the border of my editText , I can add gradient but it takes the entire background . How can I apply gradient only to the border , and the rest should be transparent?
This one does the trick :)
<?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:angle="45"
android:endColor="#0256FC"
android:centerColor="#0256FC"
android:startColor="#FE00B1" />
<corners android:radius="4dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<size
android:width="162dp"
android:height="44dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#color/colorWhite" />
<corners android:radius="4dp" />
<size
android:width="50dp"
android:height="50dp" />
</shape>
</item>
</layer-list>
Add the edittext in a layout
Set gradient background color for that layout
Set margin 1dp for edittext.
Set white background for edittext
i think now it's displays like your expectation, thank you
Create your button_border.xml and keep it within drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- view border color and width -->
<stroke
android:width="1dp"
android:color="#color/white" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp" >
</corners>
</shape>
Now set your editText background as follows :
android:background="#drawable/button_border"

How to use image for background of shape?

I have a shape (rectangle) for ListItem selector:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#eef0f3" />
<corners
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp" />
</shape>
It's rectangle with color #eef0f3, but I need use background image instead of:
<solid android:color="#eef0f3" />
How can I to do this?
You could use a layer-list instead of a shape.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/button_image" />
<item>
<shape android:shape="rectangle">
<corners
android:bottomRightRadius="4dp"
android:bottomLeftRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp"/>
</shape>
</item>
You will also need to add rounded corners to the image. To do this, look up:
How to make an ImageView with rounded corners?

How to position radial gradient background

How can I position a radial gradient shape as background in a LinearLayout ? Here is what I presently have :
The shape :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="#e6e6e6"
android:gradientRadius="800"
android:startColor="#fafaf9"
android:type="radial"/>
</shape>
The LinearLayout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/accueil_bg_gradient">
</LinearLayout>
I just want to have my gradient starting from the left upper corner of the screen, and ending at the right lower corner.
Thanks a lot !
You can move the middle of the radial gradient at a different position of the drawable using "centerX" and "centerY" attributes of the gradient. They are a floating point values ranging from 0 to 1.0 where (values of centerX,centerY accordingly) 0,0 is upper left and 1,1 is bottom right corner.
Default is 0.5,0.5 which is the middle of the drawable / assigned space.
Example for a 100px long (radius), black-white gradient whose middle starts at upper left corner would be:
<shape android:shape="rectangle">
<gradient
android:type="radial"
android:startColor="#ffffff"
android:endColor="#000000"
android:gradientRadius="100"
android:angle="270"
android:centerX="0"
android:centerY="0"/>
</shape>
set this as background mybackground.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" android:layout_width="wrap_content">
<stroke android:width="10dp" android:color="#color/darkBlue" />
<solid android:color="#00000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient android:startColor="#color/grayBlue"
android:endColor="#color/lightBlue" android:angle="270"
android:centerColor="#color/lightBlue" />
<!-- border width and color -->
<stroke android:width="1dp" android:color="#FFDDDDDD" />
<padding android:left="10dp" android:top="8dp" android:right="10dp"
android:bottom="8dp" />
</shape>
</item>
</layer-list>

Categories

Resources