0

I want to have 3 circular buttons horizontally with equal margins. I tried setting programmatically but I get NPE since view was not drawn.

How can I do it in layout file? I tried below but is not circle.

Place 3 buttons in a LinearLayout to occupy equal amount of space

Please help.

Community
  • 1
  • 1
GJain
  • 5,025
  • 6
  • 48
  • 82
  • http://stackoverflow.com/questions/17823582/circular-buttons-in-linearlayoutvertical had the answer for me – GJain Feb 11 '17 at 10:05

2 Answers2

1

Use like this

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>
    </FrameLayout>

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>
    </FrameLayout>

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>
    </FrameLayout>
</LinearLayout>

Apply style to your buttons

Hemanth S
  • 669
  • 6
  • 16
0

You can try this.

circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <corners android:radius="10dip"/>
    <stroke android:color="#FF0000" android:width="5dip"/>
    <solid android:color="#FF0000"/>
</shape>

Put this inside the drawable folder and set this as background of your buttons (added like in the accepted answer of the link).

Hope this helps

Valentino
  • 2,125
  • 1
  • 19
  • 26