Azlan Jamal
Azlan Jamal

Reputation: 2818

How to draw complex button with inset circle in xml?

How to draw button like below image in xml? Basically, it has two different buttons. One is for I. another one is for Pick Up. Thanks.enter image description here

Upvotes: 0

Views: 197

Answers (2)

ᴛʜᴇᴘᴀᴛᴇʟ
ᴛʜᴇᴘᴀᴛᴇʟ

Reputation: 4656

Try this. Example image is shown.

Note: you will have to fix the path to make the image perfect.

enter image description here

button_circle.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="@android:color/darker_gray" />
</shape>

button_rectangle.xml

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="720dp"
    android:height="576dp"
    android:viewportWidth="720"
    android:viewportHeight="576">

    <path
        android:fillColor="@android:color/darker_gray"
        android:pathData="M700.461,426.359c0,51.164-7.764,92.641-17.336,92.641H76.369
c-9.575,0,17.191-101.692,17.191-152.855l-1.444-173.699c0-51.164-25.321-136.646-15.747-136.646h606.756
c9.572,0,17.336,41.476,17.336,92.64V426.359z" />
</vector>

You will have to fix the vector to make the shape perfect. but this a good example for u.

my_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="match_parent"
        android:layout_height="42dp"
        android:background="@drawable/button_rectangle"/>

    <Button
        android:layout_width="42dp"
        android:layout_height="42dp"
        android:background="@drawable/button_circle"/>
</RelativeLayout>

Hope this helps!

Upvotes: 3

RoShan Shan
RoShan Shan

Reputation: 2954

Try this:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/bg_btn_coner"
            android:gravity="center"
            android:text="Pickup"
            android:textColor="@android:color/white"
            android:textSize="20sp" />

        <TextView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/bg_btn_coner"
            android:gravity="center"
            android:text="i"
            android:textColor="@android:color/white"
            android:textSize="20sp" />


    </RelativeLayout>

and bg_btn_coner.xml

<solid android:color="#737373" />

<stroke
    android:width="3dp"
    android:color="@android:color/white"></stroke>

<corners android:radius="50dp"></corners>

Result: enter image description here

Upvotes: 3

Related Questions