package com.autotech.we1l.tools;

import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

public class ParallaxPageTransformer extends BaseTransformer {

    public ParallaxPageTransformer() {
    }

    @Override
    protected void onTransform(View view, float position) {
    }

    @Override
    public void transformPage(@NonNull View view, float position) {
        if (view instanceof ViewGroup)
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++)
                if (position > -1 && position < 1) {
                    float childWidth = ((ViewGroup) view).getChildAt(i).getWidth();
                    ((ViewGroup) view).getChildAt(i).setTranslationX(-(position * childWidth * 0.5f));
                }
    }
}