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

Suggestion: freeze / unfreeze view #46

Closed
usernotnull opened this issue Dec 2, 2016 · 4 comments
Closed

Suggestion: freeze / unfreeze view #46

usernotnull opened this issue Dec 2, 2016 · 4 comments

Comments

@usernotnull
Copy link

I stumbled upon some errors while I'm performing ObjectAnimator animations on kenburnsview, mainly, I was expanding/collapsing the view.
Each time the height field changed, the image view was stuttering, reloading the image or transition on it.
I always got IncompatibleRatioException: can't perform effect on rects with distinct aspect ratios.
I tried to resolve it by setting the image to null, then by setting the transition generator to null (but that didn't work so instead I set it to a new generator with method to return; immediately without calculations, but that also crashed for another reason, because the library needs values from that method).

Eventually I thought about suggesting a method which freezes the layout so that no calculations or redraws are done. This is helpful in advanced situations such as collapsing/expanding/animating the bounds of kenburnsview, even with height/width of zero.
Of course, an unfreeze method after animations are completed.

@flavioarfaria
Copy link
Owner

Have you tried calling kbv.pause() before performing your animation?

@usernotnull
Copy link
Author

That was in fact the first thing I tried, then null image, then null generator. The exception was thrown each time.

@flavioarfaria
Copy link
Owner

The library was not created with view transformations in mind. This is because the transition will break if the view bounds change. There may not exist enough image surface to accomodate extra space that a view gains when its dimensions increase. Besides that, it would be cumbersome to force custom generators to support it.

Make sure you really need to deal with bound animation, sometimes you can achieve the same effect by using translations instead, just by overlaying your KBV with a sibling view. However, if you REALLY need to change bounds, there's something you could try, but I'm not sure if it'll work:

  1. Before you start your animation, grab a snapshot of the view by calling kbv.getDrawingCache(). You may need to callbuildDrawingCache() right before, but I'm not sure.
  2. Add a regular ImageView to your hierarchy exactly on top of your KenBurnsView and make it display the cached bitmap.
  3. Animate the regular ImageView.
  4. Now replace the old KenBurnsView with a new one with new bounds and then hide the regular ImageView.

As a side effect, you'll have a transition mismatch after this animation, since you're now dealing with a different KBV.

@usernotnull
Copy link
Author

Thanks for the suggestion, I guess I will go for that. For now I just put the visibility to Gone, the parent view will just scale down and I'll later attempt to put a dummy imageview as you said. I'll post again here if I found a better solution for future reference.

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

No branches or pull requests

2 participants