2016-06-03 6 views
1

내가 얻으려고하는 것은 imageView에서 이미지를로드 할 때 scaleType = "centerCrop"과 비슷한 전체 이미지 뷰를 채워야하지만 센터 인 경우 가로 이미지 일 경우 왼쪽으로 자르거나 세로면 트리밍해야합니다. 그런 다음 천천히 이동하여 이미지의 잘린 부분을 천천히 표시해야합니다.전체 이미지에 이미지 맞추기 숨겨진 부분을 보여주기 위해 애니메이션 적용

이 그림과 동일합니다.

enter image description here

은 내가 필요한 인이 딜레마

KenburnsView

유일한 문제는 TransitionGenerator에 대한 포괄적 인 설명을 제공하지 않는 문서입니다 좀 도와 수있는 라이브러리를 발견하고 나는 나 자신을 알아 내기에는 너무 멍청하다. 인터넷 검색을 시도했지만 this 만 찾을 수있었습니다.

이 라이브러리를 사용해 보셨습니까? 올바른 방향으로 나를 가리킬 수 있습니까 아니면 유사한 기능을 가진 다른 라이브러리가 있다면 알려주십시오. 감사.

답변

0

저는 최근 APP에서 동일한 필요성을 가지고 있습니다.

KenBurnsView의 소스 코드를 읽은 후, 여기 는 가능한 TransitionGenerator입니다 :

public static class ScanTransitionGenerator implements TransitionGenerator { 
    private static final int DEFAULT_TRANSITION_DURATION = 5000; 
    private static final Interpolator DEFAULT_TRANSITION_INTERPOLATOR = new AccelerateDecelerateInterpolator(); 

    private long transitionDuration; 
    private Interpolator transitionInterpolator; 
    private Transition lastTransition; 
    private RectF lastDrawableBounds; 
    private boolean forward; 

    public ScanTransitionGenerator() { 
     transitionDuration = DEFAULT_TRANSITION_DURATION; 
     transitionInterpolator = DEFAULT_TRANSITION_INTERPOLATOR; 
    } 

    @Override 
    public Transition generateNextTransition(RectF drawableBounds, RectF viewport) { 
     float drawableRatio = getRectRatio(drawableBounds); 
     float viewportRectRatio = getRectRatio(viewport); 
     RectF startRect; 
     RectF endRect; 
     if (drawableRatio >= viewportRectRatio) { 
      float w = drawableBounds.height() * viewportRectRatio; 
      float h = drawableBounds.height(); 
      startRect = new RectF(0, 0, w, h); 
      endRect = new RectF(drawableBounds.width() - w, 0, drawableBounds.width(), h); 
     } else { 
      float w = drawableBounds.width(); 
      float h = drawableBounds.width()/viewportRectRatio; 
      startRect = new RectF(0, 0, w, h); 
      endRect = new RectF(0, drawableBounds.height() - h, w, drawableBounds.height()); 
     } 

     if (!drawableBounds.equals(lastDrawableBounds) || !haveSameAspectRatio(lastTransition.getDestinyRect(), viewport)) { 
      forward = false; 
     } 
     forward = !forward; 

     if (forward) { 
      lastTransition = new Transition(startRect, endRect, transitionDuration, transitionInterpolator); 
     } else { 
      lastTransition = new Transition(endRect, startRect, transitionDuration, transitionInterpolator); 
     } 

     lastDrawableBounds = new RectF(drawableBounds); 
     return lastTransition; 
    } 

    private static boolean haveSameAspectRatio(RectF r1, RectF r2) { 
     return (Math.abs(getRectRatio(r1) - getRectRatio(r2)) <= 0.01f); 
    } 

    private static float getRectRatio(RectF rect) { 
     return rect.width()/rect.height(); 
    } 
} 
관련 문제