Skip to content

Instantly share code, notes, and snippets.

@yuriyskulskiy
Created August 14, 2020 17:49
Show Gist options
  • Save yuriyskulskiy/d9f9b3cc460f471cf7156fa1f54e55b3 to your computer and use it in GitHub Desktop.
Save yuriyskulskiy/d9f9b3cc460f471cf7156fa1f54e55b3 to your computer and use it in GitHub Desktop.
AnimatedLayout_part_2 update child during scrolling
private void updateOffset(float newOffsetValue) {
...
updateIconView();
}
private void updateIconView() {
float oldTranslatePosition = mWeatherIcon.getTranslationX();
float newTranslatePosition;
float newAlpha;
if (mOffsetValue < getWidth() / 2f) {
newTranslatePosition = mOffsetValue;
if (oldTranslatePosition > 0) {
applyWinterIcon();
}
float alphaPass = getWidth() / 2f;
newAlpha = 1 - newTranslatePosition / alphaPass;
} else {
newTranslatePosition = mOffsetValue - getWidth();
if (oldTranslatePosition < 0) {
applySummerIcon();
}
float alphaPass = getWidth() / 2f;
newAlpha = 1 + newTranslatePosition / alphaPass;
mWeatherIcon.setAlpha(newAlpha);
}
mWeatherIcon.setAlpha(newAlpha);
mWeatherIcon.setTranslationX(newTranslatePosition);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment