team-supercharge / ShimmerLayout

DEPRECATED - Memory efficient shimmering effect for Android applications by Supercharge.
Apache License 2.0
2.51k stars 282 forks source link

Animation not working properly when add background #61

Closed CHRehan closed 6 years ago

CHRehan commented 6 years ago

When i add background color animation ripple collapsed with other Views screenshot_1532159074

veghtomi commented 6 years ago

@CHRehan I would say it's not a bug, but a feature. Basically, we have a shader which contains the Lineargradient(shimmer line) and a bitmap which contains the bounds of everything which is not transparent. And in every frame, we blend these 2 together. Since your ShimmerLayout has a background color, when we blend it together with the Lineargradient you can see the whole shimmer line as we don't have to cut out parts to match what is not transparent.

The solution for this is to embed ShimmerLayoutin another ViewGroupwhich contains the background color. Or a better one to use ConstraintLayoutas a parent, so you can easily position a simple View behind ShimmerLayoutwith a background color. In this way, you avoid nesting Views.

LOG-TAG commented 6 years ago

@veghtomi Howto use it when ConstraintLayout as a parent and 4 child card views = https://gist.github.com/LOG-TAG/dc13db135724d9738c8664e432c85cb5

inside that cardview gain ConstraintLayout with widgets texviews? just after declaring the parent put the ShimmerLayout and close before parent closes?

veghtomi commented 6 years ago

@LOG-TAG The easiest way if you want to animate only the contents of the CardView is the following. Add a ShimmerLayout as a child of the CardView, and after add the contents (ConstraintLayout) as the child of ShimmerLayout. The ConstraintLayout and ShimmerLayout should have a transparent background, so the animation will only appear on the Views and TextViews. If you want to modify the background, add one to the CardView, so it will not interfere with the animation.

Just write me if you have more questions!