Shadow shadow for ViewPager

Background: I have DropShadowFrameLayoutin my application, which is a container used only to paint a shadow over its child views. Like a shadow above and below ListView, you know.

It is based on this article: http://proandroiddev.blogspot.ru/2012/01/android-design-tip-drop-shadows-on.html

Cyril Mottier also offers the same approach: http://cyrilmottier.com/2012/06/08/the-making-of-prixing-3-polishing-the-sliding-app-menu/

It just overrides dispatchDraw(Canvas canvas)to draw a shadow bitmap above it.

I have VerticalViewPager( https://github.com/castorflex/VerticalViewPager ) inside DropShadowFrameLayout, and the problem is that it deepens the view hierarchy (which is already complex), causing glitches to scroll.

What I tried: I decided to get rid of this DropShadowFrameLayoutby moving the shadow drawing code directly to dispatchDraw(Canvas canvas)in ViewPager. And the problem here is that it ViewPager draws the shadow only on the fact that the child is initially visible, and when I scroll through it, the shadow moves with it. Of course, this is not the behavior that I expect, because the shadows should be motionless while the performances for children are being watched.

This method worked well with ListView.

Question: how to apply this method to ViewPager? Or is there another way to do this, which is tantamount to performance? Or at least why does behavior ViewPagerbehave this way?

+4
source share
1 answer

The problem was that the shadows were DropShadowFrameLayoutalways drawn in a fixed position:

private Rect getDropShadowArea(Canvas canvas, Bitmap bm) { return new Rect(0, 0, canvas.getWidth(), bm.getHeight()); }

ViewPagerit turned out that it uses its internal coordinates, so the solution was to set up this method to know the current scroll position ViewPager(I use Y instead of X, because I actually use it VerticalViewPager, but the principle is the same for both):

private Rect getDropShadowArea(Canvas canvas, Bitmap bm) { return new Rect(0, getScrollY(), canvas.getWidth(), getScrollY() + bm.getHeight()); }

canvas getScrollY() , ( pskink).

() , dispatchDraw() Bitmap.

0

Source: https://habr.com/ru/post/1530198/


All Articles