ViewPager利润率PageTransformer转换 [英] ViewPager margin in PageTransformer transformations

查看:216
本文介绍了ViewPager利润率PageTransformer转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ViewPager,其中每个它的观点是卡在甲板上的再presentation。每张卡都有使用ViewPager利润率边框阴影:

I have a ViewPager in which each of it's views is a representation of card on a deck. Each card has a shadow on the border using the ViewPager margin:

cardsViewPager.setPageMargin(getResources().getDisplayMetrics().widthPixels / 20);
cardsViewPager.setPageMarginDrawable(R.drawable.shadow);

和它工作正常。

但是,如果我添加PageTransformer使得右侧的卡将堆叠在卡片顶端的左

But, if I add a PageTransformer so that the cards on the right will stack on top of the cards on the left:

public class ScalePageTransformer implements PageTransformer {  
    private final ViewPager mViewPager;

    public ScalePageTransformer(ViewPager viewPager) {
        this.mViewPager = viewPager;
    }

    @Override
    public void transformPage(View page, float position) {
        if (position <= 0) {
            int pageWidth = mViewPager.getWidth();
            final float translateValue = position * -pageWidth;
            if (translateValue > -pageWidth) {
                page.setTranslationX(translateValue);
            } else {
                page.setTranslationX(0);
            }
        }
    }
}

我这样做是:

I do this by:

cardsViewPager.setPageTransformer(false, new ScalePageTransformer(cardsViewPager));

但现在,保证金不会出现。如果我有缩小作用,对PageTransformer,我可以看到在当前卡正在缩小,该保证金可绘制是当前卡片在屏幕上下方。这里是一个事先知情同意来描述发生了什么:

But now, the margin does not appear. If I had a zoom out effect on the PageTransformer, I can see when the current card is being scaled down, that the margin drawable is below the current card on the screen. Here is a pic to describe what's happening:

蓝卡正在从以留在红牌顶部的右侧刷卡。由于红牌具有一定的规模改造,我们可以看到黑色的边缘绘制它的后面。

The blue card is being swiped from the right to left on top of the red card. Since the red card has a scale transformation, we can see the margin drawable in black behind it.

有没有办法强制边缘绘制要对红牌的顶部?如果不是这是默认的行为?

Is there a way to force the margin drawable to be on top of the red card? Shouldn't this be the default behavior?

推荐答案

更​​改为

cardsViewPager.setPageTransformer(true, new ScalePageTransformer(cardsViewPager));

第一个参数是绘制顺序

First argument is the drawing order

这篇关于ViewPager利润率PageTransformer转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆