Reputation: 1080
I am tryin to make a circle button with image, also i want to add seperator background them. I can create a circle button but i have no idea how to add image and separator on this.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:text="New Button"
android:id="@+id/button"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:text="New Button"
android:id="@+id/button2"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:text="New Button"
android:id="@+id/button3"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:text="New Button"
android:id="@+id/button4"
android:layout_weight="1" />
</LinearLayout>
Round_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="oval">
<solid android:color="#0dbe00"/>
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="#c20586"/>
</shape>
</item>
</selector>
What i want :
What i have :
Upvotes: 1
Views: 6284
Reputation: 182
Try this
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:weightSum="4">
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/round_button"
android:text="1"
android:id="@+id/button"/>
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/round_button"
android:text="2"
android:id="@+id/button2"/>
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/round_button"
android:text="3"
android:id="@+id/button3"/>
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/round_button"
android:text="4"
android:id="@+id/button4"/>
</LinearLayout>
And round_button:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="ring">
<solid android:color="#0dbe00"/>
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="ring">
<solid android:color="#c20586"/>
</shape>
</item>
</selector>
Upvotes: 4
Reputation: 2727
Try to:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:text="New Button"
android:id="@+id/button"/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:text="New Button"
android:id="@+id/button2" />
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:text="New Button"
android:id="@+id/button3" />
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_button"
android:text="New Button"
android:id="@+id/button4" />
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
Upvotes: 0
Reputation: 157487
also i want to add seperator background them. I can create a circle button but i have no idea how to add image and separator on this.
to add an image to the Button you can use android:src
to separate the items you could add a View
between the buttons. E.g.
<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
Upvotes: 0