I'm trying to create a custom shape for my NavigationView
footer, as background. but it's not so clean. This is what I have done:
And this is what I need:
Code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:gravity="bottom">
<shape android:shape="rectangle">
<solid android:color="@color/darkerGray" />
</shape>
</item>
<item
android:gravity="bottom|center_horizontal"
android:top="50dp">
<!--android:top="-40dp"-->
<shape android:shape="oval">
<solid android:color="#ffffffff" />
</shape>
</item>
<item
android:bottom="30dp"
android:gravity="bottom">
<shape android:shape="rectangle">
<solid android:color="#ffffffff" />
</shape>
</item>
Can you help me, please?
#. Update your custom
drawable
XML as below:PREVIEW:
#. Use this custom
drawable
in your layout as below:OUTPUT:
Hope this will help~
I would use a vector drawable to achieve this.
The
pathData
attribute here is relatively straightforward:You can adjust the appearance of the curve (how deep it goes) by fiddling with the first two numbers after the "a" (i.e.
a13 7
); these are the x-radius and the y-radius. A larger x-radius will make the curve flatter overall, and a larger y-radius will make the curve go farther down into the square.The path starts at a negative y-axis value because we're (currently) using an x-radius that's larger than half of our shape, so the arc needs to be adjusted up so that it hits (0,0) when it first appears. Consequently, if you modify the x-radius you will also have to modify the origin of the path (the numbers after the initial "M", i.e.
M0 -5.4
).