androidradio-groupandroid-radiogroupsegmentedcontrol

SegmentedGroup - last button is squeezed


I am using segmented control from https://github.com/Kaopiz/android-segmented-control and it works quite fine except last button is always squeezed like this:

segmented control

I am adding RadioButtons dynamically using simple layout:

<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    style="@style/RadioButton" />

I tried variations like Layout_width="wrap content" and removing "layout_weight" - same result. Parent layout of the segmented control itself also gives no hints:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@color/white"
        android:gravity="center"
        android:minHeight="60dp">

        <info.hoang8f.android.segmented.SegmentedGroup
            android:id="@+id/segmentedGroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            segmentedgroup:sc_border_width="1dp"
            segmentedgroup:sc_corner_radius="10dp"
            segmentedgroup:sc_tint_color="#FFEB3B">


        </info.hoang8f.android.segmented.SegmentedGroup>
    </RelativeLayout>

Solution

  • Answer found by chance at this topic: Programmatically-added RadioButtons refuse to obey LayoutParams weighting

    Just setting layout params programmatically before adding Button to RadioGroup reached the desired effect:

      RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
        radioButton.setLayoutParams(layoutParams);