Android Open Source - oidarSample Zoom Out Page Transformer






From Project

Back to project page oidarSample.

License

The source code is released under:

GNU General Public License

If you think the Android project oidarSample listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.oidar.animation;
//  ww w  .j a  v a2 s . c  om
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * Source from here http://developer.android.com/training/animation/screen-slide.html
 */
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {

    private static final float MIN_SCALE = 0.85f;
    private static final float MIN_ALPHA = 0.5f;

    public void transformPage(View view, float position) {
        int pageWidth = view.getWidth();
        int pageHeight = view.getHeight();

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

        } else if (position <= 1) { // [-1,1]
            // Modify the default slide transition to shrink the page as well
            float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
            float vertMargin = pageHeight * (1 - scaleFactor) / 2;
            float horzMargin = pageWidth * (1 - scaleFactor) / 2;
            if (position < 0) {
                view.setTranslationX(horzMargin - vertMargin / 2);
            } else {
                view.setTranslationX(-horzMargin + vertMargin / 2);
            }

            // Scale the page down (between MIN_SCALE and 1)
            view.setScaleX(scaleFactor);
            view.setScaleY(scaleFactor);

            // Fade the page relative to its size.
            view.setAlpha(MIN_ALPHA +
                    (scaleFactor - MIN_SCALE) /
                            (1 - MIN_SCALE) * (1 - MIN_ALPHA));

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




Java Source Code List

com.oidar.ApplicationTest.java
com.oidar.activity.MainActivity.java
com.oidar.activity.SettingsActivity.java
com.oidar.activity.base.BaseActivity.java
com.oidar.adapter.DrawerAdapter.java
com.oidar.adapter.DrawerLiveNewsAdapter.java
com.oidar.adapter.DrawerTalkRadioAdapter.java
com.oidar.animation.CustomObjectAnimator.java
com.oidar.animation.DepthPageTransformer.java
com.oidar.animation.ZoomOutPageTransformer.java
com.oidar.fragment.AboutFragment.java
com.oidar.fragment.DrawerLiveNewsFragment.java
com.oidar.fragment.DrawerTalkRadioFragment.java
com.oidar.fragment.FeedbackFragment.java
com.oidar.fragment.LiveNewsFragment.java
com.oidar.fragment.SettingsFragment.java
com.oidar.fragment.TalkRadioFragment.java
com.oidar.fragment.base.DrawerFragment.java
com.oidar.fragment.base.RadioFragment.java
com.oidar.model.DrawerListItem.java
com.oidar.model.ListItemType.java
com.oidar.model.Radio.java
com.oidar.sql.SqlHandler.java
com.oidar.util.Constants.java
com.oidar.util.MathHelper.java
com.oidar.util.MyLog.java
com.oidar.util.OIDARConstants.java
com.oidar.util.PreferenceUtil.java
com.oidar.util.StringHelper.java
com.oidar.util.Util.java
com.oidar.view.CustomDrawerLayout.java