gpt4 book ai didi

具有 DepthPageTransformer z-index 问题的 Android viewpager

转载 作者:行者123 更新时间:2023-11-29 15:12:53 35 4
gpt4 key购买 nike

我用 DepthPageTransformer 实现了一个 viewpager,在页面中我有一些输入( radio 、复选框、选择选项...)。它工作正常,除了一个有线错误:有时当我点击页面 P1 上的位置(x,y)时,页面 P2 的那个位置的输入被触发。

P1:

page P1

P2(P1之后的那个):

P2 the page after p1

现在当我点击页面 P1 上的这个位置时:

enter image description here

我得到页面 P2 显示的选择选项:

enter image description here

类似于web开发中的z-index问题。

DepthPage 转换器的代码与文档中的代码相同:http://developer.android.com/training/animation/screen-slide.html#pagetransformer .

public class DepthPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.75f;
@Override
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();

if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);

} else if (position <= 0) { // [-1,0]
// Use the default slide transition when moving to the left page
view.setAlpha(1);
view.setTranslationX(0);
view.setScaleX(1);
view.setScaleY(1);

} else if (position <= 1) { // (0,1]
// Fade the page out.
view.setAlpha(1 - position);

// Counteract the default slide transition
view.setTranslationX(pageWidth * -position);

// Scale the page down (between MIN_SCALE and 1)
float scaleFactor = MIN_SCALE
+ (1 - MIN_SCALE) * (1 - Math.abs(position));
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);

} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}

关于如何解决这个重叠问题的任何想法?

最佳答案

试试这个:

public class DepthPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.75f;
@Override
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();

if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);

} else if (position <= 0) { // [-1,0]
// Use the default slide transition when moving to the left page
view.setAlpha(1);
view.setTranslationX(0);
view.setScaleX(1);
view.setScaleY(1);
// -------- THIS LINE ---
view.bringToFront();
// -------- THIS LINE ---

} else if (position <= 1) { // (0,1]
// Fade the page out.
view.setAlpha(1 - position);

// Counteract the default slide transition
view.setTranslationX(pageWidth * -position);

// Scale the page down (between MIN_SCALE and 1)
float scaleFactor = MIN_SCALE
+ (1 - MIN_SCALE) * (1 - Math.abs(position));
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);

} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}

关于具有 DepthPageTransformer z-index 问题的 Android viewpager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28672992/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com