2014-01-08 6 views
1

특정 뷰의 높이 변화를 애니메이션화하려고합니다. Evaluator를 사용하여 ValueAnimator를 설정하고 애니메이션의 모든 패스에서 LayoutParams를 업데이트합니다. 이것은 requestLayout() 호출을 트리거합니다. 그러나 레이아웃 패스가 완료되기 전에 애니메이션의 다음 패스는 LayoutParams를 업데이트하고 다른 requestLayout()을 트리거합니다. 결과는 LogCat에서 출력되는 경고와 애니메이션이 잘 작동하지 않는 것입니다. 많은 프레임을 건너 뛰는 것 같습니다.ValueAnimator를 사용하여 LayoutParams에 애니메이션을 적용하면 requestLayout()이 부적절하게 호출 됨

ValueAnimator contentHeightAnimator = ValueAnimator.ofObject(new HeightEvaluator(mContentView), 
      mContentView.getMeasuredHeight(), (int) (getMeasuredHeight() - (actionBarHeight + destinationY))); 
    contentHeightAnimator.setDuration(duration); 
    contentHeightAnimator.setInterpolator(mInterpolator); 
    contentHeightAnimator.start(); 

... 

private static class HeightEvaluator extends IntEvaluator { 

    private View mView; 

    public HeightEvaluator(View v) { 
     this.mView = v; 
    } 

    @Override 
    public Integer evaluate(float fraction, Integer startValue, Integer endValue) { 
     int num = (Integer) super.evaluate(fraction, startValue, endValue); 
     ViewGroup.LayoutParams params = mView.getLayoutParams(); 
     params.height = num; 
     mView.setLayoutParams(params); 
     return num; 
    } 

} 

레이아웃 변경 사항을 적용하는 가장 좋은 방법은 무엇입니까?

답변

0

여기에 낮은 수준의 메뉴가

final int newBottomMargin = (int)(origBottomMargin + halfMargin); 
    final int newTopMargin = (int)(origTopMargin + halfMargin); 

    splitUp = new Animation() { 
     @Override 
     protected void applyTransformation(float interpolatedTime, Transformation t) { 
      LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) btnShopWireless.getLayoutParams(); 
      params.bottomMargin = (int)(newBottomMargin * interpolatedTime); 
      btnShopWireless.setLayoutParams(params); 
     } 
    }; 

    splitDown = new Animation() { 
     @Override 
     protected void applyTransformation(float interpolatedTime, Transformation t) { 
      LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) btnShopBundles.getLayoutParams(); 
      params.topMargin = (int)(newTopMargin * interpolatedTime); 
      btnShopBundles.setLayoutParams(params); 
     } 
    }; 

를 삽입 할 수있는 또 다른 있도록 내가 메뉴 분할을 애니메이션을 사용 하나