In my Android project, I have a ListView
with rows containing SwitchCompat
items (AppCompat for Switch
widget).
My problem occurs when I scroll into the list and getView(...)
method of MyAdapter
is invoked with a recycled
view. I redefine the correct Switch
state but the animation is visible.
There is a solution to prevent the animation in this case?
To chage it to a default state you may link each state to “Exit”, then the state is infinitely called again. If it want to change the “Stay” animation, a parameter of Animator need to be initialized. You change the parameter to “Stay” value after switching a state. If a project is simple action game, the above code have nothing problem.
If it want to change the “Stay” animation, a parameter of Animator need to be initialized. You change the parameter to “Stay” value after switching a state.
Environment: Unity 2018.4.6f How to use Animator “Any State”. The way for simple action game. Take measure for continuous inputs as combat game. A state linked to “Any State” can transition from all states. But if it’s just linked by “make transition”, same animation is called many times. It need uncheck “ Can Transition To Self “.
But if it’s just linked by “make transition”, same animation is called many times. It need uncheck “ Can Transition To Self “. This parameter is on a cursor of transition. The state isn’t called many times but at the end of animation a model just stand.
Call jumpDrawablesToCurrentState()
to skip the animation
switchCompat.setChecked(true); switchCompat.jumpDrawablesToCurrentState();
I finally found a solution but seems not really clean:
ViewGroup viewGroup = (ViewGroup) view; // the recycled view viewGroup.removeView(switch); switch.setChecked(states[index]); viewGroup.addView(switch);
If a better solution exists, please share it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With