In my project, I would like to animate a background with a large image template endlessly as follows:

At first I used a matrix (for scaling and translation) using ValueAnimator to create a translation animation, but I have no idea how to repeat the template.
What is the way to develop this effect? Thank you for your help.
Update, my source code without repetition (Note: in the GIF animation, I drew the image template horizontally to simplify the presentation, but in reality I need animation with vertical translation):
background.setImageResource(R.drawable.background);
background.setScaleType(ScaleType.MATRIX);
ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
private Matrix matrix = new Matrix();
@Override public void onAnimationUpdate(ValueAnimator animation) {
float factor = (Float) animation.getAnimatedValue();
int width = background.getDrawable().getIntrinsicWidth();
int height = background.getDrawable().getIntrinsicHeight();
float scale = (float) background.getWidth() / (float) width;
matrix.reset();
matrix.postTranslate(0, -height * factor);
matrix.postScale(scale, scale);
background.setImageMatrix(matrix);
}
});
animator.setInterpolator(new LinearInterpolator());
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.RESTART);
animator.setDuration(10000);
animator.start();
source
share