Page curl not working in Action bar tabs

孤者浪人 提交于 2019-11-29 09:01:48

ActionBar tabs are deprecated in 5.0

Perhaps a page transform that doesn't break for use with a viewpager.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mPager.setPageTransformer(true, new DepthPageTransformer());
    }



public class DepthPageTransformer implements ViewPager.PageTransformer {

private static final String TAG="DepthTransformer";
private static float MIN_SCALE = 0.75f;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    Log.d(TAG, "VIew " + view + " Position: " + position);

    if (position <= -1) { // [-Infinity,-1) ] ***

        // RLP> I Changed to include "-1" as well: When position is -1, the view is not visible

        // This page is way off-screen to the left.

        view.setAlpha(0);
        Log.d(TAG, "VIew "+view+" Position: "+position+", way left");
        view.setVisibility(View.GONE);

    } 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);
        if (position==0) {
            Log.d(TAG, "View "+view+" focused now?");
        }

        if (view.getVisibility()!=View.VISIBLE)
            view.setVisibility(View.VISIBLE);

    } else if (position <= 1) { // (0,1]

        // Fade the page out.
        view.setAlpha(1 - position);

        // Counteract the default slide transition

        // I THINK THIS IS WHAT BREAKS EVERYTHING
        // ViewPager normally has the views one after another, but this makes all views on top

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

        if (position==1) {

            Log.d(TAG, "View "+view+" invisible now?");
            view.setVisibility(View.GONE);
            // we totally hide the view. This seems to solve focus issue

        } else {
            if (view.getVisibility()!=View.VISIBLE)
                view.setVisibility(View.VISIBLE);
        }

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

        // we totally hide the view. This seems to solve focus issue
        // I have to check for strange side-effects, but so far I found none :)

        view.setVisibility(View.GONE);

        Log.d(TAG, "VIew "+view+" Position: "+position+", way right");
    }
}
}

Harism's page curl is designed for bitmaps, not for views. With that module, it is not possible to reach what you want, unless your tab contains only bitmaps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!