Last active
January 24, 2018 09:06
-
-
Save jrejaud/d955b1330c996f87fdb3 to your computer and use it in GitHub Desktop.
Android RadioGroup center custom images, keeping aspect ratio, with constant spacing between them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This lets you space out your radio buttons to have a constant space between them while keeping the aspect ratio of an image | |
<RadioGroup | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal"> | |
<RadioButton | |
style="@style/radio_button_transport" | |
android:background="@drawable/transport_mode_button_foot"/> | |
<Space | |
style="@style/radio_button_spacer" /> | |
<RadioButton | |
style="@style/radio_button_transport" | |
android:background="@drawable/transport_mode_button_bicycle"/> | |
<Space | |
style="@style/radio_button_spacer" /> | |
<RadioButton | |
style="@style/radio_button_transport" | |
android:background="@drawable/transport_mode_button_scooter"/> | |
<Space | |
style="@style/radio_button_spacer" /> | |
<RadioButton | |
style="@style/radio_button_transport" | |
android:background="@drawable/transport_mode_button_car"/> | |
<Space | |
style="@style/radio_button_spacer" /> | |
<RadioButton | |
style="@style/radio_button_transport" | |
android:background="@drawable/transport_mode_button_truck"/> | |
</RadioGroup> | |
<!-- Styles --> | |
<style name="radio_button_spacer"> | |
<item name="android:layout_width">0dp</item> | |
<item name="android:layout_height">match_parent</item> | |
<item name="android:layout_weight">1</item> | |
</style> | |
<style name="radio_button_transport"> | |
<item name="android:layout_width">wrap_content</item> | |
<item name="android:layout_height">wrap_content</item> | |
<item name="android:button">@null</item> | |
</style> | |
<!-- Example background file --> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_checked="true" android:drawable="@drawable/settings_transport_mode_bicycle_active" /> | |
<item android:drawable="@drawable/settings_transport_mode_bicycle" /> | |
</selector> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment