Giter Site home page Giter Site logo

segmentedbutton's Introduction

Android Arsenal

Archived

I stopped developing this library for a long time ago. I thought about revising it recently but there is already someone keeping it up. I recommend you to use it instead. Thank you all for your support.

https://github.com/addisonElliott/SegmentedButton

SegmentedButton

poster

Segmented Button is a IOS-like "Segmented Control" with animation.
For more Android-like segmented control, check Radio Real Button.

Preview

1
2
3
6
4 5

You can also apply your custom drawable on button group

7

It is now possible to drag selector

8

Installation

Gradle

Add it to your build.gradle with:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

and:

dependencies {
    compile 'com.github.ceryle:SegmentedButton:v2.0.2'
}

Customization

Some Attributes

Segmented Button

Option Name Format Description
app:sb_imageTint color Set tint onto button's image
app:sb_imageScale float Scale button's image
app:sb_selectedImageTint color Set tint onto button's image if selector on it
app:sb_selectedTextColor color Set color onto button's text if selector on it
app:sb_rippleColor color Set ripple color of button

Segmented Button Group

Option Name Format Description
app:sbg_ripple boolean Set ripple color for every button
app:sbg_rippleColor color Set ripple color for every button with custom color
app:sbg_selectorImageTint color If selector on it, set tint onto image for every button
app:sbg_selectorTextColor color If selector on it, set text color for every button
app:sbg_selectorColor color Set selector color
app:sbg_dividerSize dimension Set divider size
app:sbg_dividerPadding dimension Set divider padding for top and bottom
app:sbg_dividerColor color Change divider color
app:sbg_dividerRadius dimension Round divider
app:sbg_shadow boolean Shadow for container layout (api21+)
app:sbg_shadowElevation dimension Shadow for container layout (api21+)
app:sbg_shadowMargin dimension Set margin to make shadow visible (api21+)
app:sbg_position integer Set selected button position
app:sbg_radius dimension Make layout rounder
app:sbg_backgroundColor color Set background color of container (except transparent color)
app:sbg_animateSelectorDuration integer Set how long selector travels to selected position
app:sbg_animateSelector integer Set selector animation (ex. bounce animation)
app:sbg_borderSize dimension Add border by giving dimension
app:sbg_borderColor color Change border color (Default: Grey)

Animations Available

  • fastOutSlowIn
  • bounce
  • linear
  • decelerate
  • cycle
  • anticipate
  • accelerateDecelerate
  • accelerate
  • anticipateOvershoot
  • fastOutLinearIn
  • linearOutSlowIn
  • overshoot

These animations can be set using the attribute noted above like so: app:sbg_animateSelector="bounce". Also make sure to play with the app:sbg_animateSelectorDuration attribute to get the animation to look exactly how you want it.

Examples

In Xml Layout
    <co.ceryle.segmentedbutton.SegmentedButtonGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        app:sbg_animateSelector="bounce"
        app:sbg_animateSelectorDuration="1000"
        app:sbg_backgroundColor="@color/white"
        app:sbg_dividerColor="@color/grey_500"
        app:sbg_dividerPadding="10dp"
        app:sbg_dividerRadius="10dp"
        app:sbg_dividerSize="1dp"
        app:sbg_position="1"
        app:sbg_radius="2dp"
        app:sbg_ripple="true"
        app:sbg_rippleColor="@color/grey_500"
        app:sbg_selectorColor="@color/grey_500"
        app:sbg_selectorTextColor="@color/white"
        app:sbg_shadow="true"
        app:sbg_shadowElevation="3dp"
        app:sbg_shadowMargin="4dp">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="10dp"
            android:text="Button 1"
            android:textAllCaps="false" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="10dp"
            android:text="Button 2"
            android:textAllCaps="false" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="10dp"
            android:text="Button 3"
            android:textAllCaps="false" />

    </co.ceryle.segmentedbutton.SegmentedButtonGroup>
Listener Example
SegmentedButtonGroup segmentedButtonGroup = (SegmentedButtonGroup) findViewById(R.id.segmentedButtonGroup);
segmentedButtonGroup.setOnClickedButtonPosition(new SegmentedButtonGroup.OnClickedButtonPosition() {
    @Override
    public void onClickedButtonPosition(int position) {
        Toast.makeText(MainActivity.this, "Clicked: " + position, Toast.LENGTH_SHORT).show();
    }
});
segmentedButtonGroup.setPosition(2, 0);

License

This project is licensed under the Apache License Version 2.0 - see the LICENSE.md file for details

segmentedbutton's People

Contributors

ceryle avatar maximeroussy avatar sys1yagi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

segmentedbutton's Issues

Small duration problem

Hi.
I haven't checked the precise value, I tried only app:sbg_animateSelectorDuration with values 0, 1. Those values make selection drawable work unexpected - selected buttons highlight randomly, we can have 2 highlighted buttons even if they're not selected etc.

getPosition() on segmentedButtonGroup obj always return 0

Hi, used your library and it's great.

Used two segmented button's inside a segmented button group. In java class file, when i apply getposition() on object of segmented button group..always return 0, irrespective of second button selected in app.
Please fix it.

And thanks once again

How do you make the buttons smaller?

Hi,

Great library looks fantastic. I tried to use the library but I couldn't get it to work for anything other than having the width set to 0 and the weight for each set to 1. how do you change the size of the buttons without is cutting of the radius edges?

Thanks

app:sbg_backgroundColor transparent as the background,

i use your library and that's was awesome...

when I was setting app:sbg_backgroundColor becomes transparent as the background, and when I run the application, the button on the left being the same as the color of the app: sbg_selectorColor

please fix it :)

Error: Draggable not working

I have 4 segmented buttons and I have set that group as draggable:true. In this case when I tap on 4th button its works but when I tap on 1st button it will show draggable at both places. In following image at first group and last Draggable segmented group layout
issue_2

Selected button loses radius

The button group has radius set with
app:sbg_radius="2dp"
but the selected button does not have a radius. I tried adding the same to the individual buttons but this does not work. I see in the gifs your buttons keep the radius when they are selected so I assume I've missed something?

Text Font

I can't change text font for <co.ceryle.segmentedbutton.SegmentedButton>

When my applications starts i get this error

Fatal Exception: java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed
at android.graphics.Canvas.checkValidClipOp(Canvas.java:789)
at android.graphics.Canvas.clipPath(Canvas.java:1017)
at co.ceryle.segmentedbutton.RoundedCornerLayout.dispatchDraw(RoundedCornerLayout.java:82)
at android.view.View.buildDrawingCacheImpl(View.java:20078)
at android.view.View.buildDrawingCache(View.java:19940)
at android.view.View.draw(View.java:20543)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at co.ceryle.segmentedbutton.SegmentedButtonGroup.dispatchDraw(SegmentedButtonGroup.java:163)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.draw(View.java:20846)
at android.view.View.updateDisplayListIfDirty(View.java:19678)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.draw(View.java:20846)
at android.widget.ScrollView.draw(ScrollView.java:1739)
at android.view.View.updateDisplayListIfDirty(View.java:19678)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.updateDisplayListIfDirty(View.java:19669)
at android.view.View.draw(View.java:20551)
at android.view.ViewGroup.drawChild(ViewGroup.java:4425)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4204)
at android.view.View.draw(View.java:20846)
at com.android.internal.policy.DecorView.draw(DecorView.java:785)
at android.view.View.updateDisplayListIfDirty(View.java:19678)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:686)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:692)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:801)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3490)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3290)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2644)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1554)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7507)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:977)
at android.view.Choreographer.doCallbacks(Choreographer.java:785)
at android.view.Choreographer.doFrame(Choreographer.java:717)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:963)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6819)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:912)

Talkback does not work properly

Hi, when I create a segmented button group, add some buttons programmatically (not in the xml) and turn on talkback from phone settings it does not work properly. Firstly, when on a button it says double tap to activate. Then, when all buttons are done with talkback and right swipe gesture is used to move to the next item, it does not continue with the next item, instead it goes back at the first button and only says the "Name of the button" + " button". Shouldn't it work like "Name of the button" + "button and double tap to activate?

Crash when the first time I open it

Asus max .
Model Number : ASUS_Z017D
Anroid 6.0.1


04-25 15:36:10.073 3655-3655/co.ceryle.segmentedbutton E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: co.ceryle.segmentedbutton, PID: 3655
                                                                         java.lang.IllegalStateException: Underflow in restore - more restores than saves
                                                                             at android.graphics.Canvas.native_restore(Native Method)
                                                                             at android.graphics.Canvas.restore(Canvas.java:540)
                                                                             at co.ceryle.segmentedbutton.SegmentedButton.onDraw(SegmentedButton.java:409)
                                                                             at android.view.View.draw(View.java:16195)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15192)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15187)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15187)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at co.ceryle.segmentedbutton.SegmentedButtonGroup.dispatchDraw(SegmentedButtonGroup.java:209)
                                                                             at android.view.View.draw(View.java:16198)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15192)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15187)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.draw(View.java:16198)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15192)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15187)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15187)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15187)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15187)
                                                                             at android.view.View.draw(View.java:15965)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
                                                                             at android.view.View.draw(View.java:16198)
                                                                             at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2690)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:15192)
                                                                             at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
                                                                             at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
                                                                             at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
                                                                             at android.view.ViewRootImpl.draw(ViewRootImpl.java:2620)
                                                                             at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2439)
                                                                             at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2072)
                                                                             at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1112)
                                                                             at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6035)
                                                                             at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                             at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                                             at android.view.Choreographer.doFrame(Choreographer.java:606)
                                                                             at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                                             at android.os.Handler.handleCallback(Handler.java:739)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                             at android.os.Looper.loop(Looper.java:148)
                                                                         	at android.a

setEnabled() does not work

The SegmentedButton is a beautiful control for Android. In some cases, I would like to disable the control. But the setEnabled(false) command does not work.
Please, can someone help me?
Thank you
Regards,
Donatello

Latest code of SegmentedButton in the library doesn't match with the gradle version.

I've tried to create a SegmentedButton with image inside the SegmentedButtonGroup, it throws me an error " app:sb_drawable" not found. I've looked into the code to find the issue, and finally found that code for SegmentedButton in the library source code is different from the version in the gradle version "com.github.ceryle:SegmentedButton:v1.2.2".

Can you please fix this.

setPosition method missing..

i found 2 issues here

  1. The setPosition method is missing when tried to use it.
  2. When i clicked, the button is switched. But when i hide and show the segmented button give original position, not the clicked position

SegmentedButton in NestedScrollView not respecting wrap_content height

Problem

When placing a SegmentedButtonGroup/SegmentedButton within a NestedScrollView, I am getting issues with the height not being set correctly even though the layout_height is set to wrap_content.

Here is an example layout, you should be able to see the issue in the layout inspector.

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">

        <co.ceryle.segmentedbutton.SegmentedButtonGroup
            android:id="@+id/buttonGroup_pickupDropoffBoth"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:duplicateParentState="false"
            android:fadeScrollbars="false"
            android:filterTouchesWhenObscured="false"
            android:fitsSystemWindows="false"
            android:focusableInTouchMode="false"
            android:hapticFeedbackEnabled="false"
            android:padding="0dp"
            app:sbg_backgroundColor="@color/white"
            app:sbg_position="0"
            app:sbg_radius="2dp"
            app:sbg_selectorColor="@color/colorPrimary87">

            <co.ceryle.segmentedbutton.SegmentedButton
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:isScrollContainer="false"
                android:padding="4dp"
                android:scrollbars="horizontal"
                app:sb_text="Both"
                app:sb_textColor="#000000"
                app:sb_textColor_onSelection="#FFFFFF" />

            <co.ceryle.segmentedbutton.SegmentedButton
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:padding="4dp"
                app:sb_text="Pickup"
                app:sb_textColor="#000000"
                app:sb_textColor_onSelection="#FFFFFF" />

            <co.ceryle.segmentedbutton.SegmentedButton
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:padding="4dp"
                app:sb_text="Dropoff"
                app:sb_textColor="#000000"
                app:sb_textColor_onSelection="#FFFFFF" />

        </co.ceryle.segmentedbutton.SegmentedButtonGroup>

    </androidx.core.widget.NestedScrollView>

</LinearLayout>

Here is a screenshot of what I see in the layout inspector:
Screenshot

See that sliver up top, yeah that is it being cut off! Commenting out NestedScrollView makes it work.

Solution

After some digging, I've found the culprit but I'm a bit confused by the source code so I need some assistance.

Regularly, the SegmentedButton will receive an onMeasure with an AT_MOST spec for the height. In this instance, it will return the following. See here for code

textHeight + 2 * paddingTop + 2 * paddingBottom

In a NestedScrollView, instead when sizing it does onMeasure with an UNSPECIFIED and SegmentedButton returns. See here for code

paddingTop + paddingBottom

Questions

@ceryle I am happy to submit a PR if we come to a conclusion for a fix.

Why does the AT_MOST return 2x padding for top/bottom while EXACTLY & UNSPECIFIED do not. This fixes the problem but I don't get the 2x so I was trying to understand.

Is it possible to change the text programmatically

Nice work,

but i have a problem. I get my text string from a database and i have to change the string while the app is running. Is it possible to change the text from the button while the app is running?
setText() doesn't work.

Tanks for help.

How to add border?

I tried to add background to SegmentedButtonGroup, however it wasn't work.
Background code:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <corners android:radius="5dp"/>
  <stroke
      android:color="@color/colorPrimary"
      android:width="1dp"
      />
</shape>

Want to behave like this library android-segmented-control.

API 28, Android 9

Hi! Thanx a lot for your awesome library. I'm using pretty old version of it:
implementation "com.github.ceryle:SegmentedButton:v1.1.3"

The app crashes on Android 9, API level 28.
Logs:

Fatal Exception: java.lang.IllegalArgumentExceptionInvalid Region.Op - only INTERSECT and DIFFERENCE are allowed Raw Text

  | android.graphics.Canvas.checkValidClipOp (Canvas.java:779)
  | android.graphics.Canvas.clipPath (Canvas.java:1007)
  | co.ceryle.segmentedbutton.RoundedCornerLayout.dispatchDraw (RoundedCornerLayout.java:82)
  | android.view.View.buildDrawingCacheImpl (View.java:19472)
  | android.view.View.buildDrawingCache (View.java:19338)
  | android.view.View.draw (View.java:19927)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.updateDisplayListIfDirty (View.java:19073)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | co.ceryle.segmentedbutton.SegmentedButtonGroup.dispatchDraw (SegmentedButtonGroup.java:193)
  | android.view.View.updateDisplayListIfDirty (View.java:19073)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.draw (View.java:20210)
  | android.view.View.updateDisplayListIfDirty (View.java:19082)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.updateDisplayListIfDirty (View.java:19073)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.draw (View.java:20210)
  | android.widget.ScrollView.draw (ScrollView.java:1739)
  | android.view.View.updateDisplayListIfDirty (View.java:19082)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.draw (View.java:20210)
  | android.view.View.updateDisplayListIfDirty (View.java:19082)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.updateDisplayListIfDirty (View.java:19073)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.updateDisplayListIfDirty (View.java:19073)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.updateDisplayListIfDirty (View.java:19073)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.updateDisplayListIfDirty (View.java:19073)
  | android.view.View.draw (View.java:19935)
  | android.view.ViewGroup.drawChild (ViewGroup.java:4333)
  | android.view.ViewGroup.dispatchDraw (ViewGroup.java:4112)
  | android.view.View.draw (View.java:20210)
  | com.android.internal.policy.DecorView.draw (DecorView.java:780)
  | android.view.View.updateDisplayListIfDirty (View.java:19082)
  | android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:686)
  | android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:692)
  | android.view.ThreadedRenderer.draw (ThreadedRenderer.java:801)
  | android.view.ViewRootImpl.draw (ViewRootImpl.java:3312)
  | android.view.ViewRootImpl.performDraw (ViewRootImpl.java:3116)
  | android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2485)
  | android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1460)
  | android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7184)
  | android.view.Choreographer$CallbackRecord.run (Choreographer.java:949)
  | android.view.Choreographer.doCallbacks (Choreographer.java:761)
  | android.view.Choreographer.doFrame (Choreographer.java:696)
  | android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:935)
  | android.os.Handler.handleCallback (Handler.java:873)
  | android.os.Handler.dispatchMessage (Handler.java:99)
  | android.os.Looper.loop (Looper.java:193)
  | android.app.ActivityThread.main (ActivityThread.java:6669)
  | java.lang.reflect.Method.invoke (Method.java)
  | com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
  | com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)

I've already tried to upgrade library to version v2.0.2, but some methods appeared not to work.
E.g. setOnClickedButtonPosition.
Could you please update wiki or somehow help me to fix this bug?

Element background leaking

If a transparent background color is set for "sbg_backgroundColor" the first button will have the same color as selectorColor.

After first clicked, Selector becomes smaller

Hello, i am using 1.2.2 When i start the activity the selector looks fine, but when i click the button or the segmented group itself, it becomes smaller and it doesnt fill the buttons.


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:orientation="horizontal">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginEnd="10dp"
        android:layout_marginRight="10dp"
        android:text="Position: 1"/>

    <co.ceryle.segmentedbutton.SegmentedButtonGroup
        android:id="@+id/segmentedButtonGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="4dp"
        android:elevation="2dp"
        app:sbg_backgroundColor="#F00"
        app:sbg_dividerColor="#FFF"
        app:sbg_dividerPadding="10dp"
        app:sbg_dividerRadius="10dp"
        app:sbg_dividerSize="12dp"
        app:sbg_position="0"
        app:sbg_radius="2dp"
        app:sbg_rippleColor="#F35"
        app:sbg_selectorColor="#0F0">

        <co.ceryle.segmentedbutton.SegmentedButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:sb_text="Button 1"/>

        <co.ceryle.segmentedbutton.SegmentedButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:sb_text="Button 2"/>

        <co.ceryle.segmentedbutton.SegmentedButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:sb_text="Button 3"/>
    </co.ceryle.segmentedbutton.SegmentedButtonGroup>

</LinearLayout>
package com.whatrecipes.dnt.whatrecipes.activities;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.whatrecipes.dnt.whatrecipes.R;

import co.ceryle.segmentedbutton.SegmentedButtonGroup;

public class ActivityTest extends AppCompatActivity {

    private Button button;
    private SegmentedButtonGroup group;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        group = (SegmentedButtonGroup) findViewById(R.id.segmentedButtonGroup);
        button = (Button) findViewById(R.id.button);

        updateButton(group.getPosition());

        group.setOnClickedButtonPosition(new SegmentedButtonGroup.OnClickedButtonPosition() {
            @Override
            public void onClickedButtonPosition(int position) {
                Toast.makeText(ActivityTest.this, "Clicked: " + position, Toast.LENGTH_SHORT).show();
            }
        });


        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int position = group.getPosition();
                position = ++position % 3;
                updateButton(position);
                group.setPosition(position, true);
            }
        });


        group.setEnabled(false);

        Handler handler = new Handler();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                group.setEnabled(true);
            }
        };
        handler.postDelayed(runnable, 5000);
    }

    private void updateButton(int position) {
        button.setText("Position: " + position);
    }
}


edit: Also the example app looks like to be using different version of SegmentedButton, than whats in 1.2.2
edit: Tried version 1.1.1 and its working fine with the same code

Selector Background not proper when divider is set .

device-2017-07-07-193435

<co.ceryle.segmentedbutton.SegmentedButtonGroup
        android:id="@+id/segment_Group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        app:sbg_backgroundColor="@android:color/white"
        app:sbg_borderColor="@android:color/black"
        app:sbg_borderSize="0.5dp"
        app:sbg_position="0"
        app:sbg_dividerSize="0.5dp"
        app:sbg_dividerColor="@android:color/black"
        app:sbg_radius="2dp"
        android:gravity="center"
        android:layout_gravity="center"
        app:sbg_animateSelectorDuration="1"
        app:sbg_selectorColor="@android:color/holo_red_dark">


    <co.ceryle.segmentedbutton.SegmentedButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="A"/>

    <co.ceryle.segmentedbutton.SegmentedButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="B"/>

    <co.ceryle.segmentedbutton.SegmentedButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="C"/>


    <co.ceryle.segmentedbutton.SegmentedButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="D"/>

    <co.ceryle.segmentedbutton.SegmentedButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="E"/>




</co.ceryle.segmentedbutton.SegmentedButtonGroup>

Please Fix .. if i increase divider size then it is leaving more space on every selected button background.

Version 2.0.1 doesn't work on target sdk 26

It compiles fine, but the button doesn't show up when running.
I reverted back to 1.2.2 and it works just fine

I didn't thorougly investigate, so i'll just give some quick info:
android studio preview 3.0
compile/targetsdk 26
occurs on device running api 25

Vertical Segmented Button Group

Is there anyway of making this segmented button group optionally layout the buttons vertically instead of just fixed horizontally?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.