I need to use custom radio buttons with background image, and space them evenly horizontally, I can achieve the spacing but cannot position the background image in the center of each button. My layout is as below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="58dp">
<RadioGroup
android:id="@+id/group_bottom_bar"
android:layout_width="match_parent"
android:layout_height="52dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/v4_btn_trip"
style="@style/BottomTabBarButtonStyle"
android:button="@drawable/v4_tabbar_radio_trip" />
<RadioButton
android:id="@+id/v4_btn_agenda"
style="@style/BottomTabBarButtonStyle"
android:button="@drawable/v4_tabbar_radio_agenda" />
<RadioButton
android:id="@+id/v4_btn_favorite"
style="@style/BottomTabBarButtonStyle"
android:button="@drawable/v4_tabbar_radio_favorite" />
<RadioButton
android:id="@+id/v4_btn_settings"
style="@style/BottomTabBarButtonStyle"
android:button="@drawable/v4_tabbar_radio_settings" />
</RadioGroup>
</RelativeLayout>
The style is per below:
<style name="BottomTabBarButtonStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:layout_weight">1</item>
I already set the gravity to center_horizontal.
I tried to replace android:button
with android:background
but that just stretched the image.
One of the selector files (v4_tabbar_radio_trip)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_bottom_tab_trip_active" android:state_checked="true" android:state_pressed="true" />
<item android:drawable="@drawable/ic_bottom_tab_trip_active" android:state_pressed="true" />
<item android:drawable="@drawable/ic_bottom_tab_trip_active" android:state_checked="true" />
<item android:drawable="@drawable/ic_bottom_tab_trip" />
</selector>
This is its current state. Update: The expected output is that the background image (the two dots) is in the middle of the greyed area (which is the radio button), not aligned to the left. Similarly for other icons