Java Code Examples for android.support.v7.widget.CardView#setScaleY()

The following examples show how to use android.support.v7.widget.CardView#setScaleY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShadowTransformer.java    From MusicPlayer_XiangDa with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }


    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1 || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);
    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        currentCard.setScaleX((1 + mScaleRatio * (1 - realOffset)));
        currentCard.setScaleY((1 + mScaleRatio * (1 - realOffset)));
        currentCard.setCardElevation(mAdapter.getMaxElevationFactor() * (1 - realOffset));
    }
    CardView nextCard = mAdapter.getCardViewAt(nextPosition);
    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        nextCard.setScaleX((1 + mScaleRatio * (realOffset)));
        nextCard.setScaleY((1 + mScaleRatio * (realOffset)));
        nextCard.setCardElevation(mAdapter.getMaxElevationFactor() * (realOffset));
    }


    if (realOffset == 1) {  //适用于:pos从0->3 ,过程中realOffset并不能至于0,所以伸缩会受到影响
        CardView cardView = null;
        if (goingLeft && nextPosition + 2 < mAdapter.getCount()) {
            cardView = mAdapter.getCardViewAt(nextPosition + 2);
        } else if (goingLeft && nextPosition - 2 > 0) {
            cardView = mAdapter.getCardViewAt(nextPosition - 2);
        }
        if (cardView != null) {
            cardView.setCardElevation(0);
            cardView.setScaleX((1));
            cardView.setScaleY((1));
        }
    }

    mLastOffset = positionOffset;
}
 
Example 2
Source File: ShadowTransformer.java    From FancyWalkthrough-Android with Apache License 2.0 4 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }

    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1
            || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);

    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }

    CardView nextCard = mAdapter.getCardViewAt(nextPosition);

    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }

    mLastOffset = positionOffset;
}
 
Example 3
Source File: ShadowTransformer.java    From ViewPagerCards with Apache License 2.0 4 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }

    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1
            || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);

    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }

    CardView nextCard = mAdapter.getCardViewAt(nextPosition);

    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }

    mLastOffset = positionOffset;
}
 
Example 4
Source File: ShadowTransformer.java    From Nimbus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }

    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1
            || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);

    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation
                * (TeamInterface.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }

    CardView nextCard = mAdapter.getCardViewAt(nextPosition);

    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation
                * (TeamInterface.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }

    mLastOffset = positionOffset;
}
 
Example 5
Source File: ShadowTransformer.java    From Dictionary with Apache License 2.0 4 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }

    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1
            || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);

    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }

    CardView nextCard = mAdapter.getCardViewAt(nextPosition);

    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }

    mLastOffset = positionOffset;
}
 
Example 6
Source File: ShadowTransformer.java    From Pano360 with MIT License 4 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }

    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1
            || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);

    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }

    CardView nextCard = mAdapter.getCardViewAt(nextPosition);

    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }

    mLastOffset = positionOffset;
}
 
Example 7
Source File: ShadowTransformer.java    From ViewPagerCards with Apache License 2.0 4 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }

    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1
            || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);

    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }

    CardView nextCard = mAdapter.getCardViewAt(nextPosition);

    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }

    mLastOffset = positionOffset;
}
 
Example 8
Source File: ShadowTransformer.java    From ahoy-onboarding with Apache License 2.0 4 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }

    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1
            || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);

    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }

    CardView nextCard = mAdapter.getCardViewAt(nextPosition);

    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }

    mLastOffset = positionOffset;
}
 
Example 9
Source File: ShadowTransformer.java    From FastAccess with GNU General Public License v3.0 4 votes vote down vote up
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;

    // If we're going backwards, onPageScrolled receives the last position
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }

    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1
            || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }

    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);

    // This might be null if a fragment is being used
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation
                * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }

    CardView nextCard = mAdapter.getCardViewAt(nextPosition);

    // We might be scrolling fast enough so that the next (or previous) card
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }

    mLastOffset = positionOffset;
}