addisonElliott / SegmentedButton

Segmented Control/Button with animation for Android API 16+
Apache License 2.0
148 stars 39 forks source link

SegmentedButton visibility issue #18

Closed draskosaric closed 4 years ago

draskosaric commented 4 years ago

I think I found the bug with this control when button is removed, ie its visibility is set to View.Gone, since the number of dividers stays the same.

This is the initial state of SegmentButtonGroup view:

Screen Shot 2019-09-11 at 2 47 33 PM

Now, I wish to change the visibility of last button (red ball and its id is "other") every time I click on "Show/hide" button:

    show_hide.setOnClickListener {
            other.visibility = if (other.visibility == View.GONE) View.VISIBLE else View.GONE
            // segmented_choices.requestLayout()
        }

No matter if I use the last line (in onClickListener example above is commented) segmented_choices.requestLayout() or not, I get the following layout:

Screen Shot 2019-09-11 at 2 54 05 PM

As you can see, the number of dividers stays the same. Is there a way to fix it?

XML layout is very simple:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

        <com.addisonelliott.segmentedbutton.SegmentedButtonGroup
                android:id="@+id/segmented_choices"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="4dp"
                app:borderColor="@color/colorPrimary"
                app:borderWidth="1dp"
                app:divider="@color/colorPrimary"
                app:dividerWidth="1dp"
                app:radius="4dp"
                app:ripple="false"
                app:selectedBackground="@color/colorPrimary"
                app:position="0"
                >
            <com.addisonelliott.segmentedbutton.SegmentedButton
                    android:id="@+id/favourites"
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    app:drawable="@drawable/sport_athletics"
                    style="@style/SegmentedItemImage"

                    />
            <com.addisonelliott.segmentedbutton.SegmentedButton
                    android:id="@+id/sport1"
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    app:drawable="@drawable/sport_football"
                    style="@style/SegmentedItemImage"
                    />
            <com.addisonelliott.segmentedbutton.SegmentedButton
                    android:id="@+id/sport2"
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    app:drawable="@drawable/sport_basketball"
                    style="@style/SegmentedItemImage"
                    />
            <com.addisonelliott.segmentedbutton.SegmentedButton
                    android:id="@+id/sport3"
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    app:drawable="@drawable/sport_icehockey"
                    style="@style/SegmentedItemImage"
                    />
            <com.addisonelliott.segmentedbutton.SegmentedButton
                    android:id="@+id/sport4"
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    app:drawable="@drawable/sport_voleyball"
                    style="@style/SegmentedItemImage"
                    />
            <com.addisonelliott.segmentedbutton.SegmentedButton
                    android:id="@+id/other"
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    app:drawable="@drawable/sport_default"
                    style="@style/SegmentedItemImage"
                    />
        </com.addisonelliott.segmentedbutton.SegmentedButtonGroup>

        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
            android:text="Show/Hide"
            android:id="@+id/show_hide"
            />
    </LinearLayout>    
addisonElliott commented 4 years ago

Hmm, I don't doubt this is a bug. I haven't done much testing or experimentation with showing or hiding buttons.

You're welcome to tackle this bug if you want, otherwise I'll get to it when I find some time (it's been hectic lately).

By the way, this was a good bug report! Just enough detail and explanation

draskosaric commented 4 years ago

Thank you very much!

addisonElliott commented 4 years ago

FYI,

I addressed this in #20. I tested on API 19, 21, 26, & 29 and it worked as expected.

New version of SegmentedButton will be released when #19 is merged in. This is likely going to be sometime next week.

A couple of notes:

draskosaric commented 4 years ago

Thanks!

draskosaric commented 4 years ago

Great, it's working now!