I am using the following below code to round the corners of RelativeLayout. I save this as mybackground.xml in drawable folder.
It's working fine for rounding the corner but the problem is that I also want to add an transparent image as a background of my RelativeLayout. How can I achieve both things? How can I use an image and a drawable xml (for rounding the corner) at the same time for a RelativeLayout ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<corners android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
use Layer List and Item tag for setting Image and use solid tag and set the color as #AA000000 for transparent as shown below
<?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="rectangle" android:padding="10dp">
<solid android:color="#AA000000"/>
<corners android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
</item>
<item>
<bitmap android:src="#drawable/yourfilename"/>
</item>
</layer-list>
You can use Layer-List
It will be like this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" android:padding="10dp">
<corners android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp" android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
</item>
<item><!-- your transparent image --></item>
</layer-list>
This one works. If you dont round corners of your pic you will not be able to see rounded corner too. Some friends talked about this in previous answers. They should round their image to see round effect.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/listviewback2">
<shape android:shape="rectangle" android:padding="10dp">
<corners
android:bottomRightRadius="35dp"
android:bottomLeftRadius="35dp"
android:topLeftRadius="35dp"
android:topRightRadius="35dp"/>
</shape>
</item>
</layer-list>
Try something like this:
<?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="rectangle" android:padding="10dp">
<corners android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp" android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
</item>
<item>
<bitmap android:src="#drawable/background"/>
</item>
</layer-list>
Related
enter image description here
XML :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<corners android:radius="20dp" />
<solid android:color="#fff" />
</shape>
</item>
</layer-list>
I want to make clipped part. How can I make the cropped piece above .
Try this :
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:bottomLeftRadius="27dp"
android:bottomRightRadius="27dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"
/>
<solid
android:color="#FFFFFF"
/>
</shape>
Modify this to be able to add a specific angle:
bottomLeftRadius
bottomRightRadius
topLeftRadius
topRightRadius
I want to make dotted line vertically with the gradient color effect. But I'm unable to do that. How can I approach. I am using this code on drawable for the dotted line
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="3px"
android:right="-5px"
android:top="-5px"
android:bottom="-5px">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="4px"
android:color="#color/colorPrimary"
android:dashGap="20px"
android:dashWidth="20px" />
</shape>
</item>
</layer-list>
Anyone knows please help
Thanks in advance
create a drawable like below
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="-5px"
android:left="3px"
android:right="-5px"
android:top="-5px">
<shape>
<gradient
android:angle="270"
android:centerColor="#00ff00"
android:endColor="#ff0000"
android:startColor="#0000ff"/>
<stroke
android:width="2dp"
android:color="#fff"
android:dashWidth="8dp"
android:dashGap="16dp"/>
</shape>
</item>
</layer-list>
now in layout you need to use a view and set this shape as background to it.
<View
android:layout_width="4dp"
android:layout_height="match_parent"
android:background="#drawable/your_shape"/>
you might need to change widht settings as per your requirements. Here is what I got
You can use shape Try this...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#000000"
android:dashWidth="10px"
android:dashGap="10px"
android:width="1dp"/>
</shape>
I want to draw a shape circular but zigzag in android as per attached image
trying this type
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/progress">
<shape
android:innerRadius="#dimen/circleProgressRadius"
android:shape="ring"
android:thickness="#dimen/circleProgressThickness">
<gradient
android:startColor="#color/circleProgressIncompleteStartGradient"
android:endColor="#color/circleProgressIncompleteEndGradient"
android:type="sweep" />
</shape>
</item>
</layer-list>
But not getting shape as per attached image How can i do this ?
edged_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="50dp" android:width="50dp" />
<stroke android:width="10dp"
android:dashGap="4dp"
android:dashWidth="1dp"
android:color="#000"/>
<solid android:color="#00000000" />
</shape>
Hope this helps, do some customizations according to your need.
P.S. size tag is just to maintain aspect ratio. Its only the stroke tag that you need to change.
To draw this image we can go like this
circle_progress_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="10dp" android:width="10dp" />
<stroke android:width="7dp"
android:dashGap="3dp"
android:dashWidth="0.5dp"
android:color="#000"/>
<solid android:color="#00000000" />
</shape>
in main activity
android:layout_width="178dp"
android:layout_height="178dp"
android:background="#drawable/circle_progress_background"
image is coming like attached snapshot
how can I create rectangle shape by using two different colors with shadow? like above image.
Please create a drawable file and put the below code in it.
<?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" />
<solid android:color="#F66D08" />
</shape>
</item>
<item android:top="50dp">
<shape android:shape="rectangle" >
<gradient android:endColor="#AD1B1D"
android:startColor="#E2360A"
android:angle="270" />
</shape>
</item>
</layer-list>
layer-list can be used to solve this
<?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="40dp"
android:height="40dp" />
<solid android:color="#F86F05" />
</shape>
</item>
<item android:top="10dp">
<shape android:shape="rectangle">
<size
android:width="30dp"
android:height="30dp" />
<solid android:color="#B31F19" />
</shape>
</item>
</layer-list>
And the screenshot of the same.
If you want gradient instead of solid color, change solid to gradient and set startColor, endColor and angle.
Place these code in your activity_main :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:gravity="center"
android:background="#F66D08"
android:layout_width="match_parent"
android:layout_height="20dp">
</LinearLayout>
<LinearLayout
android:background="#drawable/introslidergradiant"
android:layout_width="match_parent"
android:layout_height="100dp"></LinearLayout>
</LinearLayout>
And create drawble res file with introslidergradiant.xml name :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#A31720"
android:endColor="#E1350B"
android:type="linear" />
</shape>
</item>
</selector>
You have to make a xml file in the drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="linear"
android:startColor="#FFFF820D"
android:endColor="#FFA32815"
android:angle="90"/>
</shape>
use the following code or you can generate your own gradient here just set the color and select the android option and it will generate the gradient for you .
I'm going to create a drawable like below image that is included an arrow image.
When I use layer-list , arrow image appear in middle of my drawable!!!
Please let me know how can I achieve it ...
UPDATE:
This is my 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">
<corners android:radius="5dp"/>
<solid android:color="#d5d5d5"/>
<stroke android:width="1dp" android:color="#242425"/>
</shape>
</item>
<item android:drawable="#drawable/ic_arrow"></item>
Make a drawable resource file set bitmap as the root element, then set the android:gravity="left" and use this bitmap file as drawable in your layer-list item.
<?xml version="1.0" encoding="utf-8"?>
<bitmap
android:gravity="left"
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ic_launcher"/>
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">
<stroke android:width="1dp" android:color="#color/blue" />
<solid android:color="#color/silver" />
</shape>
</item>
<item android:drawable="#drawable/stack" />
</layer-list>