Android的viewpager与DepthPageTrans

Android的viewpager与DepthPageTrans

本文介绍了Android的viewpager与DepthPageTransformer z-index的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个viewpager与DepthPageTransformer,在网页我有一些输入(收音机,检查boxs,选择选项...)。它的工作原理除了一个有线的错误罚款:有时,当我在页面P2的那个位置上的一个页面P1点击位置(X,Y)输入被触发。

I implemented a viewpager with a DepthPageTransformer , in pages I have some inputs ( radio , check boxs , select options ... ). It works fine except one wired bug: Sometimes when I click on position(x,y) on a page P1 the input in that position of page P2 gets triggered.

P1:

P2(P1后一个):

P2( the one after P1):

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

Now when I click on this position on page P1 :

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

I get the select options displayed of page P2:

这是在Web开发类似于z-index的问题。

It's similar to z-index problem in web development.

在DepthPage变压器的code是一样的文档:的.

The code of the DepthPage Transformer is the same as in the documentation : 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);
    }
}
}

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

Any idea on how to solve this overlapping problem ?

推荐答案

试试这个:

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);
}
}
}

这篇关于Android的viewpager与DepthPageTransformer z-index的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:18