Home » Android » Android shape border with gradient and middle transparent

Android shape border with gradient and middle transparent

Posted by: admin May 14, 2020 Leave a comment

Questions:

I need to create a round corner border, where border with gradient.enter link description here is working.But My page is using a image as background which is also with gradient. I need to show background image from middle of the filed. I want to create just like below image:enter image description here

How to&Answers:

round_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
<stroke
    android:width="4dp"
    android:color="@color/transparent" />
    <gradient
        android:startColor="#374533"
        android:centerColor="#432727"
        android:endColor="#222430"
        android:angle="135"/>
    <corners android:radius="10dp" />
</shape>

round_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">

<gradient
    android:startColor="#efe301"
    android:centerColor="#7dc17b"
    android:endColor="#01dae6"
    android:angle="180"/>
<corners android:radius="10dp" />

result_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:drawable="@drawable/round_border"/>
  <item android:drawable="@drawable/round_background" />

</layer-list>

Here, you can set android:width=”4dp” in round_background.xml to set size of your border. use result result_drawable.xml where you want..
Enjoy. :}