Last active
January 18, 2018 13:33
-
-
Save hatamiarash7/96b6e91e3d3c8297fa7201b57dec0baa to your computer and use it in GitHub Desktop.
Android Animated Background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final ImageView backgroundOne = (ImageView) findViewById(R.id.background_one); | |
final ImageView backgroundTwo = (ImageView) findViewById(R.id.background_two); | |
final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, 1.0f); | |
animator.setRepeatCount(ValueAnimator.INFINITE); | |
animator.setInterpolator(new LinearInterpolator()); | |
animator.setDuration(10000L); | |
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator animation) { | |
final float progress = (float) animation.getAnimatedValue(); | |
final float height = backgroundOne.getHeight(); | |
final float translationY = height * progress; | |
backgroundOne.setTranslationY(translationY); | |
backgroundTwo.setTranslationY(translationY - height); | |
} | |
}); | |
animator.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:id="@+id/background_one" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:scaleType="centerCrop" | |
android:src="@drawable/animate_background"/> | |
<ImageView | |
android:id="@+id/background_two" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:scaleType="centerCrop" | |
android:src="@drawable/animate_background"/> | |
</FrameLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment