滑动视图保持在视图寻呼机的顶部

时间:2015-11-18 05:49:03

标签: android android-viewpager

使用ViewPager处理旋转木马的ui视图,只修改了FlickableStackView库。我发现滑动视图保持在顶部,那么如何让视图落在主视图后面?

下面是transformPage函数:

@Override
public void transformPage(View view, float position) {

    int dimen = 0;
    switch (mOrientation) {
        case VERTICAL:
            dimen = view.getHeight();
            break;
        case HORIZONTAL:
            dimen = view.getWidth();
            break;
    }

    if (!mInitialValuesCalculated) {
        mInitialValuesCalculated = true;
        calculateInitialValues(dimen);
    }

    switch (mOrientation) {
        case VERTICAL:
            view.setRotationX(0);
            view.setPivotY(dimen / 2f);
            view.setPivotX(view.getWidth() / 2f);
            break;
        case HORIZONTAL:
            view.setRotationY(0);
            view.setPivotX(dimen / 2f);
            view.setPivotY(view.getHeight() / 2f);
            break;
    }

    if (position < -mNumberOfStacked - 1) {
        view.setAlpha(0f);
    } else if (position <= 0) {
        float scale = mZeroPositionScale + (position * mStackedScaleFactor);
        float baseTranslation = (-position * dimen);
        float shiftTranslation = calculateShiftForScale(position, scale, dimen);
        view.setScaleX(scale);
        view.setScaleY(scale);
        if(position<=-1){
            view.setScaleX(scale-0.1f);
            view.setPivotY(dimen/4f);
            view.setRotationX(-30);
        }
        view.setAlpha(1.0f + (position * mAlphaFactor));
        switch (mOrientation) {
            case VERTICAL:
                view.setTranslationY(baseTranslation + shiftTranslation);
                break;
            case HORIZONTAL:
                view.setTranslationX(baseTranslation + shiftTranslation);
                break;
        }
    } else if (position <= 1+mNumberOfStacked) {
        float scale = mZeroPositionScale - (position * mStackedScaleFactor);
        float baseTranslation = (-position * dimen);
        float shiftTranslation = calculateShiftForScale(position, scale, dimen);
        view.setScaleX(scale);
        view.setScaleY(scale);
        if(position>=1){
            view.setScaleX(scale-0.1f);
            view.setPivotY(dimen-dimen/4f);
            view.setRotationX(+30);
        }
        view.setAlpha(1.0f - (position * mAlphaFactor));
        switch (mOrientation) {
            case VERTICAL:
                view.setTranslationY(baseTranslation + 2*shiftTranslation);
                break;
            case HORIZONTAL:
                view.setTranslationX(baseTranslation + 2*shiftTranslation);
                break;
        }
        /*float baseTranslation = position * dimen;
        float scale = mZeroPositionScale - mValueInterpolator.map(mScaleInterpolator.getInterpolation(position));
        scale = (scale < 0) ? 0f : scale;
        float shiftTranslation = (1.0f - position) * mOverlap;
        float rotation = -mRotationInterpolator.getInterpolation(position) * 90;
        rotation = (rotation < -90) ? -90 : rotation;
        float alpha = 1.0f - position;
        alpha = (alpha < 0) ? 0f : alpha;
        view.setAlpha(alpha);
        switch (mOrientation) {
            case VERTICAL:
                view.setPivotY(dimen);
                view.setRotationX(rotation);
                view.setScaleX(mZeroPositionScale);
                view.setScaleY(scale);
                view.setTranslationY(-baseTranslation - mBelowStackSpace - shiftTranslation);
                break;
            case HORIZONTAL:
                view.setPivotX(dimen);
                view.setRotationY(-rotation);
                view.setScaleY(mZeroPositionScale);
                view.setScaleX(scale);
                view.setTranslationX(-baseTranslation - mBelowStackSpace - shiftTranslation);
                break;
        }*/
    } else if (position > 1+mNumberOfStacked) {
        view.setAlpha(0f);
    }
}

0 个答案:

没有答案