Java Code Examples for android.support.v4.view.ViewPager#PageTransformer

The following examples show how to use android.support.v4.view.ViewPager#PageTransformer . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VerticalViewPager.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
/**
 * Set a {@link android.support.v4.view.ViewPager.PageTransformer} that will be called for each
 * attached page whenever
 * the scroll position is changed. This allows the application to apply custom property
 * transformations to each page, overriding the default sliding look and feel.
 * <p/>
 * <p><em>Note:</em> Prior to Android 3.0 the property animation APIs did not exist.
 * As a result, setting a PageTransformer prior to Android 3.0 (API 11) will have no effect.</p>
 *
 * @param reverseDrawingOrder true if the supplied PageTransformer requires page views
 * to be drawn from last to first instead of first to last.
 * @param transformer PageTransformer that will modify each page's animation properties
 */
public void setPageTransformer(boolean reverseDrawingOrder,
    ViewPager.PageTransformer transformer) {
  if (Build.VERSION.SDK_INT >= 11) {
    final boolean hasTransformer = transformer != null;
    final boolean needsPopulate = hasTransformer != (mPageTransformer != null);
    mPageTransformer = transformer;
    setChildrenDrawingOrderEnabledCompat(hasTransformer);
    if (hasTransformer) {
      mDrawingOrder = reverseDrawingOrder ? DRAW_ORDER_REVERSE : DRAW_ORDER_FORWARD;
    } else {
      mDrawingOrder = DRAW_ORDER_DEFAULT;
    }
    if (needsPopulate) populate();
  }
}
 
Example 2
Source File: VerticalInfiniteCycleViewPager.java    From InfiniteCycleViewPager with Apache License 2.0 5 votes vote down vote up
@Override
public void setPageTransformer(final boolean reverseDrawingOrder, final ViewPager.PageTransformer transformer) {
    super.setPageTransformer(
            false, mInfiniteCycleManager == null ?
                    transformer : mInfiniteCycleManager.getInfinityCyclePageTransformer()
    );
}
 
Example 3
Source File: BGAViewPager.java    From KUtils with Apache License 2.0 4 votes vote down vote up
@Override
public void setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer) {
    /**
     继承ViewPager,重写setPageTransformer方法,移除版本限制,通过反射设置参数和方法

     getDeclaredMethod*()获取的是【类自身】声明的所有方法,包含public、protected和private方法。
     getMethod*()获取的是类的所有共有方法,这就包括自身的所有【public方法】,和从基类继承的、从接口实现的所有【public方法】。

     getDeclaredField获取的是【类自身】声明的所有字段,包含public、protected和private字段。
     getField获取的是类的所有共有字段,这就包括自身的所有【public字段】,和从基类继承的、从接口实现的所有【public字段】。
     */
    Class viewpagerClass = ViewPager.class;

    try {
        boolean hasTransformer = transformer != null;

        Field pageTransformerField = viewpagerClass.getDeclaredField("mPageTransformer");
        pageTransformerField.setAccessible(true);
        PageTransformer mPageTransformer = (PageTransformer) pageTransformerField.get(this);

        boolean needsPopulate = hasTransformer != (mPageTransformer != null);
        pageTransformerField.set(this, transformer);

        Method setChildrenDrawingOrderEnabledCompatMethod = viewpagerClass.getDeclaredMethod("setChildrenDrawingOrderEnabledCompat", boolean.class);
        setChildrenDrawingOrderEnabledCompatMethod.setAccessible(true);
        setChildrenDrawingOrderEnabledCompatMethod.invoke(this, hasTransformer);

        Field drawingOrderField = viewpagerClass.getDeclaredField("mDrawingOrder");
        drawingOrderField.setAccessible(true);
        if (hasTransformer) {
            drawingOrderField.setInt(this, reverseDrawingOrder ? 2 : 1);
        } else {
            drawingOrderField.setInt(this, 0);
        }

        if (needsPopulate) {
            Method populateMethod = viewpagerClass.getDeclaredMethod("populate");
            populateMethod.setAccessible(true);
            populateMethod.invoke(this);
        }
    } catch (Exception e) {
    }
}
 
Example 4
Source File: ScaleInTransformer.java    From Android-Application-ZJB with Apache License 2.0 4 votes vote down vote up
public ScaleInTransformer(ViewPager.PageTransformer pageTransformer) {
    this(DEFAULT_MIN_SCALE, pageTransformer);
}
 
Example 5
Source File: ScaleInTransformer.java    From MagicViewPager with Apache License 2.0 4 votes vote down vote up
public ScaleInTransformer(float minScale, ViewPager.PageTransformer pageTransformer)
{
    mMinScale = minScale;
    mPageTransformer = pageTransformer;
}
 
Example 6
Source File: BGAViewPager.java    From KUtils-master with Apache License 2.0 4 votes vote down vote up
@Override
public void setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer) {
    /**
     继承ViewPager,重写setPageTransformer方法,移除版本限制,通过反射设置参数和方法

     getDeclaredMethod*()获取的是【类自身】声明的所有方法,包含public、protected和private方法。
     getMethod*()获取的是类的所有共有方法,这就包括自身的所有【public方法】,和从基类继承的、从接口实现的所有【public方法】。

     getDeclaredField获取的是【类自身】声明的所有字段,包含public、protected和private字段。
     getField获取的是类的所有共有字段,这就包括自身的所有【public字段】,和从基类继承的、从接口实现的所有【public字段】。
     */
    Class viewpagerClass = ViewPager.class;

    try {
        boolean hasTransformer = transformer != null;

        Field pageTransformerField = viewpagerClass.getDeclaredField("mPageTransformer");
        pageTransformerField.setAccessible(true);
        PageTransformer mPageTransformer = (PageTransformer) pageTransformerField.get(this);

        boolean needsPopulate = hasTransformer != (mPageTransformer != null);
        pageTransformerField.set(this, transformer);

        Method setChildrenDrawingOrderEnabledCompatMethod = viewpagerClass.getDeclaredMethod("setChildrenDrawingOrderEnabledCompat", boolean.class);
        setChildrenDrawingOrderEnabledCompatMethod.setAccessible(true);
        setChildrenDrawingOrderEnabledCompatMethod.invoke(this, hasTransformer);

        Field drawingOrderField = viewpagerClass.getDeclaredField("mDrawingOrder");
        drawingOrderField.setAccessible(true);
        if (hasTransformer) {
            drawingOrderField.setInt(this, reverseDrawingOrder ? 2 : 1);
        } else {
            drawingOrderField.setInt(this, 0);
        }

        if (needsPopulate) {
            Method populateMethod = viewpagerClass.getDeclaredMethod("populate");
            populateMethod.setAccessible(true);
            populateMethod.invoke(this);
        }
    } catch (Exception e) {
    }
}
 
Example 7
Source File: AlphaPageTransformer.java    From MagicViewPager with Apache License 2.0 4 votes vote down vote up
public AlphaPageTransformer(ViewPager.PageTransformer pageTransformer)
{
    this(DEFAULT_MIN_ALPHA, pageTransformer);
}
 
Example 8
Source File: RotateYTransformer.java    From MagicViewPager with Apache License 2.0 4 votes vote down vote up
public RotateYTransformer( ViewPager.PageTransformer pageTransformer)
{
    this(DEFAULT_MAX_ROTATE, pageTransformer);
}
 
Example 9
Source File: IntroActivity.java    From Pasta-Music with Apache License 2.0 4 votes vote down vote up
@Override
public ViewPager.PageTransformer getPageTransformer() {
    return TutorialFragment.getParallaxPageTransformer(2.5f);
}
 
Example 10
Source File: BGABanner.java    From KUtils with Apache License 2.0 4 votes vote down vote up
/**
 * 设置自定义页面切换动画
 *
 * @param transformer
 */
public void setPageTransformer(ViewPager.PageTransformer transformer) {
    if (transformer != null && mViewPager != null) {
        mViewPager.setPageTransformer(true, transformer);
    }
}
 
Example 11
Source File: IntroActivity.java    From Prodigal with Apache License 2.0 4 votes vote down vote up
public void setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer) {
    pager.setPageTransformer(reverseDrawingOrder, transformer);
}
 
Example 12
Source File: ScaleInTransformer.java    From MagicViewPager with Apache License 2.0 4 votes vote down vote up
public ScaleInTransformer(ViewPager.PageTransformer pageTransformer)
{
    this(DEFAULT_MIN_SCALE, pageTransformer);
}
 
Example 13
Source File: RotateDownPageTransformer.java    From MagicViewPager with Apache License 2.0 4 votes vote down vote up
public RotateDownPageTransformer(ViewPager.PageTransformer pageTransformer)
{
    this(DEFAULT_MAX_ROTATE, pageTransformer);
}
 
Example 14
Source File: WidgetPager.java    From relight with Apache License 2.0 4 votes vote down vote up
public WidgetPager pageTransformer(boolean reverseDrawingOrder, @Nullable ViewPager.PageTransformer transformer, int pageLayerType) {
    view.setPageTransformer(reverseDrawingOrder, transformer, pageLayerType);
    return self();
}
 
Example 15
Source File: XBanner.java    From XBanner with Apache License 2.0 4 votes vote down vote up
/**
 * 自定义翻页动画效果
 * @param transformer
 */
public void setCustomPageTransformer(ViewPager.PageTransformer transformer) {
    if (transformer != null && mViewPager != null) {
        mViewPager.setPageTransformer(true, transformer);
    }
}
 
Example 16
Source File: RotateUpPageTransformer.java    From MagicViewPager with Apache License 2.0 4 votes vote down vote up
public RotateUpPageTransformer(ViewPager.PageTransformer pageTransformer)
{
    this(DEFAULT_MAX_ROTATE, pageTransformer);
}
 
Example 17
Source File: PlaybarPagerTransformer.java    From SwipePlaybarDemo with Apache License 2.0 4 votes vote down vote up
public void addTransformer(ViewPager.PageTransformer transformer) {
    if (transformer != null) {
        mTransformers.add(transformer);
    }
}
 
Example 18
Source File: StepperLayout.java    From android-material-stepper with Apache License 2.0 2 votes vote down vote up
/**
 * Overrides the default page transformer used in the underlying {@link com.stepstone.stepper.internal.widget.StepViewPager}.
 * If you're supporting RTL make sure your {@link android.support.v4.view.ViewPager.PageTransformer} accounts for it.
 *
 * @param pageTransformer new page transformer
 * @see com.stepstone.stepper.internal.widget.StepViewPager
 * @see com.stepstone.stepper.internal.widget.pagetransformer.StepPageTransformerFactory
 */
public void setPageTransformer(@Nullable ViewPager.PageTransformer pageTransformer) {
    mPager.setPageTransformer(false, pageTransformer);
}
 
Example 19
Source File: ItHeiMaDialog.java    From GuideDialog with MIT License 2 votes vote down vote up
/**
 * 设置ViewPager切换动画方式
 * @param pageTransformer
 * @return
 */
public ItHeiMaDialog setPageTransformer(ViewPager.PageTransformer pageTransformer) {
    mPageTransformer = pageTransformer;
    return this;
}
 
Example 20
Source File: TutorialActivity.java    From Pasta-Music with Apache License 2.0 votes vote down vote up
public abstract ViewPager.PageTransformer getPageTransformer();