ViewPager margin in PageTransformer transformations(PageTransformer 转换中的 ViewPager 边距)
问题描述
我有一个 ViewPager,其中的每个视图都是卡片组上卡片的表示.每张卡片的边框上都有一个使用 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);
}
}
}
}
我这样做是:
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));
第一个参数是绘制顺序
这篇关于PageTransformer 转换中的 ViewPager 边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PageTransformer 转换中的 ViewPager 边距


基础教程推荐
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01