ValueAnimator 및 setTranslationX를 "두 이미지"로 사용하십시오. Android move background continuously with animation
는 또한, 귀하의 경우, 당신은 방향 스크롤 변경해야
이 참조. 아래의 "수정 됨"에 유의하십시오.
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); // Modified
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 width = backgroundOne.getWidth();
final float translationX = width * progress;
backgroundOne.setTranslationX(translationX);
backgroundTwo.setTranslationX(translationX - width);
}
});
animator.start();
EDIT1
: 당신은 서버에서 이미지를 사용하려는 경우
, 난 당신이 피카소 이미지 라이브러리를 사용하는 것이 좋습니다. http://square.github.io/picasso/
파일을 Build.gradle 피카소 종속성을 추가합니다. '피카소 : 2.5.2 com.squareup.picasso'안드로이드 스튜디오 피카소와
이미지로드의 상단의
- 를 눌러 동기화 버튼 (
- 종속 관계로 아래
컴파일 추가 . final ImageView backgroundOne = (ImageView) findViewById(R.id.background_one);
final ImageView backgroundTwo = (ImageView) findViewById(R.id.background_two);
Picasso.with(this).load("http://www.talk4u.in/wp-content/uploads/2017/02/cropped-logo2.png").into(backgroundOne);
Picasso.with(this).load("http://www.talk4u.in/wp-content/uploads/2017/02/cropped-logo2.png").into(backgroundTwo);
final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, -1.0f); // Modified
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 width = backgroundOne.getWidth();
final float translationX = width * progress;
backgroundOne.setTranslationX(translationX);
backgroundTwo.setTranslationX(translationX - width);
}
});
animator.start();
- 인터넷에 액세스 할 수있는 네트워크 권한을 추가합니다.
오, 고맙습니다. cricket_007. 나는 그 코드 블록을 고칠 수 없었다. –