Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPager seems to reenable clipChildren when scrolling if PageTransformer is set

I have a ViewPager with both clipToPadding and clipChildren set to false. The items in the pager have a drop shadow effect that is drawn below each item, outside of its bounds. This works just fine when the pager is static:

enter image description here

However, when animating between pages the children are clipped just as if clipChildren has been set:

enter image description here

The behaviour only occurs when the PageTransformer is set.

like image 843
BarneyBear Avatar asked Oct 29 '14 09:10

BarneyBear


1 Answers

After digging around for quite a while i found the following post here on Stack overflow: Do not clip ViewPager pages. While similar, i did not suffer from the NoSaveStateFrameLayout issue the poster had. However in the comment to the accepted answer I found the following tidbit:

"[...] I had a PageTransformer on my ViewPager, but you couldn't know. I set the layer on my transformed View to NONE, and it worked."

So I tried doing the following in my PageTransformer:

public void transformPage(View view, float v) {

    view.setLayerType(View.LAYER_TYPE_NONE, null);
}

This finally solved the problem. It should be noted that setting this when creating the element did not solve the problem.

like image 156
BarneyBear Avatar answered Oct 11 '22 11:10

BarneyBear