2017-03-04 13 views
-3

http://www.talk4u.in/TagoreAcadmy/marque.html마키 이미지와 같은 이미지 슬라이더를 만들고 싶습니까?

HTML 형식으로되어이 내 URL이 지금은 그런 이미지 슬라이더를 bulid 원하지만 내가 좋아하는 결말까지 .I이 다시 시작되어야합니다 안드로이드보기 및 이미지 이동을 사용하여 개발하려는 웹보기를 사용하지 않으 글로브.

나는 천칭 같은 슬라이더에 표시하는 것보다 mysql 데이터베이스에서 다중 이미지 URL을 가져 왔습니다.

감사합니다.

답변

1

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/

  1. 파일을 Build.gradle 피카소 종속성을 추가합니다. '피카소 : 2.5.2 com.squareup.picasso'안드로이드 스튜디오 피카소와

  2. 이미지로드의 상단의

  3. 를 눌러 동기화 버튼 (

    • 종속 관계로 아래
      컴파일 추가 .

      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(); 
      
      • 인터넷에 액세스 할 수있는 네트워크 권한을 추가합니다.
+0

오, 고맙습니다. cricket_007. 나는 그 코드 블록을 고칠 수 없었다. –