0

I am look for the right way to create this kind of custom buttons in android (xml).enter image description here

I know i can set this image as a background for a button, but i am look for a way to re-create it with xml to make it be responsive for various screen sizes.

AouledIssa
  • 2,528
  • 2
  • 22
  • 39
  • I think you will have solution for this at [here](http://stackoverflow.com/questions/23483060/android-responsive-image-button-layout) – Bui Quang Huy Mar 15 '16 at 01:42
  • That was not what i was looking for, what i'm attamping to have is that exact design written in xml. Thanks for the reply anyway – AouledIssa Mar 15 '16 at 01:51

1 Answers1

2

You could use a layer-list to achieve that design using XML. Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="60dp">
    <shape>
        <size
            android:width="200dp"
            android:height="120dp"/>
        <gradient
            android:startColor="#474946"
            android:endColor="#181818"
            android:angle="270"/>
        <corners android:topLeftRadius="2dp" android:topRightRadius="2dp"
            android:bottomLeftRadius="2dp" android:bottomRightRadius="2dp"/>
    </shape>
</item>
<item android:right="140dp">
    <shape android:shape="oval">
        <size
            android:width="120dp"
            android:height="120dp"/>
        <solid android:color="#000000"/>
    </shape>
</item>

You can also use a 9-patch for that.

Natan
  • 1,867
  • 13
  • 24
  • thank you for this code i'll give it a try. But i'm just curious if a 9 patch image would behave in the right way when stretched ? – AouledIssa Mar 15 '16 at 16:48