Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SegmentedButton visibility issue #18

Closed
draskosaric opened this issue Sep 11, 2019 · 5 comments · Fixed by #20
Closed

SegmentedButton visibility issue #18

draskosaric opened this issue Sep 11, 2019 · 5 comments · Fixed by #20

Comments

@draskosaric
Copy link

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
Copy link
Owner

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
Copy link
Author

Thank you very much!

addisonElliott added a commit that referenced this issue Sep 14, 2019
Little experimentation was done with showing or hiding buttons and the functionality. It was extremely buggy, with animations not working correctly and dividers not updating properly.

This PR adds proper support for showing and hiding buttons via SegmentedButton.setVisibility function.

Fixes #18
@addisonElliott
Copy link
Owner

addisonElliott commented Sep 14, 2019

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:

  • It's up to the developer to make sure the currently selected button is not being hidden. Otherwise, nothing will be selected once that button is hidden. If you want to hide the current button, just change the selected button to be to the left or right of that one.
  • SegmentedButton.setVisibility can be used as expected to show and hide the buttons.
  • Some weird results are likely to occur if the button is being animated from one spot to the next and a button is shown/hidden simultaneously
  • I tested this PR as much as I could, but it's not improbable there is bugs. Please let me know and I can fix them as they come up!

@draskosaric
Copy link
Author

Thanks!

@draskosaric
Copy link
Author

Great, it's working now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants