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.

2
  • I think you will have solution for this at here Commented Mar 15, 2016 at 1: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 Commented Mar 15, 2016 at 1:51

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.