Vamshidhar R Vamshidhar R - 4 months ago 12
Android Question

How to make a button pointing towards right or left?

I wish to use a button of this shape,pointing to right or left in my app.

Two corners of the button are rounded, and the other side is triangular.

I was able to accomplish this somewhat using a png image as background, but I would prefer to know how to do it in xml.

enter image description here

Answer

Not sure about the exact way to do that, but you could always increase the radius of the topLeft and bottomLeft or Right to maximum, to get a semicircular pointing end. This is how I tried to do it

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:topLeftRadius="100dp"
android:topRightRadius="31dp"
android:bottomLeftRadius="100dp"
android:bottomRightRadius="31dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="#7995A8"
android:startColor="#E8E8E8"
android:endColor="#000000"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="172dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
</shape> 

This is how it looks..

Comments