How to speed up or turn off animation of RadioButton on Android?
Asked Answered
X

1

6

I have a RadioGroup with dynamically added RadioButtons. In my Activity, I close the activity immediately after a RadioButton is selected. However, this leads to an artifact where two RadioButtons look like they are selected before the Activity finishes. The previous selection and current selection are both still animating when the Activity finishes.

Is there a way to speed up the animation or disable it altogether so that I don't see this visual artifact?

radioButton.setChecked(true);   // previous selected button is still deselecting and current button is now selecting. both are in the middle of animating but activity closes before they can finish animating  
finishWithResult(selected == null ? Activity.RESULT_CANCELED : Activity.RESULT_OK, selectedItem);
Xylia answered 12/1, 2017 at 17:19 Comment(0)
S
1

In order to allow the user to see the selection of the RadioButton they've selected you can delay closing the Activity instead of turning off the RadioButton selection animation.

radioGroup.setOnCheckedChangeListener { radioGroup, checkedId ->
    Handler(Looper.getMainLooper()).postDelayed(
        {
            finish()
        },
        500
    )
}

If you would like to remove the animation regardless, you can see the answer here: https://mcmap.net/q/1917845/-how-to-prevent-checkbox-animation-after-setting-the-value

E.g.

radioGroup.setOnCheckedChangeListener { radioGroup, checkedId ->
    radioGroup.jumpDrawablesToCurrentState()
}
Spectacle answered 10/7, 2021 at 0:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.