nex3z / ToggleButtonGroup

A group of flowable toggle buttons, with multiple / single selection support and button customization.
Apache License 2.0
421 stars 49 forks source link

layout_weight #31

Closed androidwanderer closed 6 years ago

androidwanderer commented 6 years ago

I am trying to get the radio buttons to fill the width of the screen equally using layout_width="0dp" and layout_weight="1". Unfortunately, this is making the Radio buttons not show. Is there a different way to accomplish this in the library? This is the sample XML I am using.

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

<com.nex3z.togglebuttongroup.SingleSelectToggleGroup
    android:id="@+id/group_single_radiobutton"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    app:tbgFlow="true">

    <RadioButton
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_weight="1"
        android:background="@drawable/selector_bg_radio_button"
        android:button="@null"
        android:gravity="left"
        android:paddingBottom="8dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="8dp"
        android:text="First"
        android:textColor="@color/colorPrimary"
       />

    <RadioButton
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_weight="1"
        android:background="@drawable/selector_bg_radio_button"
        android:button="@null"
        android:gravity="center"
        android:paddingBottom="8dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="8dp"
        android:text="Second"
        android:textColor="@color/colorPrimary"
       />
</com.nex3z.togglebuttongroup.SingleSelectToggleGroup>

`

nex3z commented 6 years ago

SingleSelectToggleGroup does not support layout_weight attribute. But you can use tbgChildSpacing="auto" to layout each button with equal margin.

For example,

<com.nex3z.togglebuttongroup.SingleSelectToggleGroup
    android:id="@+id/group_choices"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tbgChildSpacing="auto"
    app:tbgCheckedButton="@+id/choice_a">

    <com.nex3z.togglebuttongroup.button.CircularToggle
        android:id="@+id/choice_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:text="A"/>

    <!--...-->

    <com.nex3z.togglebuttongroup.button.CircularToggle
        android:id="@+id/choice_d"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:text="D"/>

</com.nex3z.togglebuttongroup.SingleSelectToggleGroup>

device-2018-05-01-222826