0

Hi there I've got a ViewPager for wich I want to enable HorizontalFadingEdge, everything works find except that it works only for the left side of the Pager. Is there a way to get the desired effect for both left and right ?

Here are some relevant snippets:

XML:

 <android.support.v4.view.ViewPager
 android:id="@+id/view_pager_preview"
 android:layout_width="match_parent"
 android:layout_height="96dp">

Setup:

 pager_preview.setClipToPadding(false);
 pager_preview.setPageMargin(-50);
 pager_preview.setHorizontalFadingEdgeEnabled(true);
 pager_preview.setFadingEdgeLength(20);

Any ideas about that ?

*Edit:

I found something like an answer to my question here: fading edges working only on top and left

Community
  • 1
  • 1
David
  • 306
  • 6
  • 20

1 Answers1

-1

try this,

viewPager.setPageTransformer(false, new ViewPager.PageTransformer() {
            @Override
            public void transformPage(View view, float position) {
                view.setTranslationX(view.getWidth() * -position);

                if(position <= -1.0F || position >= 1.0F) {
                    view.setAlpha(0.0F);
                } else if( position == 0.0F ) {
                    view.setAlpha(1.0F);
                } else {
                    // position is between -1.0F & 0.0F OR 0.0F & 1.0F
                    view.setAlpha(1.0F - Math.abs(position));
                }
            }
        });
Pradeep Gupta
  • 1,770
  • 1
  • 9
  • 23
  • Funny but when I add your code the fragments fade from behind. I mean they are all layered with specified alpha and just get to the front when swiping. Maybe explain what this snippet is doing. – David Apr 14 '16 at 14:17
  • it simply set a alpha with value when page is slide. – Pradeep Gupta Apr 14 '16 at 14:28
  • Okay any idea why this code changes the position of the fragments ? – David Apr 14 '16 at 14:58