2017-04-07 7 views
1

クリックがあるときにビューの高さをmatch_parentに変更するにはどうすればよいですか?androidのアニメーションと一致する高さのビューを設定

public class ResizeAnimation extends Animation { 
    final int startHeight; 
    final int targetHeight; 
    private final boolean isOpen; 
    View view; 

    public ResizeAnimation(View view, int height, boolean isOpen) { 
     this.view = view; 
     this.targetHeight = height; 
     this.isOpen = isOpen; 
     startHeight = view.getHeight(); 
    } 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     int newHeight; 
     if (isOpen) { 
      newHeight = (int) (startHeight + (targetHeight - startHeight) * interpolatedTime); 
     } else { 
      newHeight = (int) (startHeight + targetHeight * interpolatedTime); 
     } 
     view.getLayoutParams().height = newHeight; 
     view.requestLayout(); 
    } 

    @Override 
    public void initialize(int width, int height, int parentWidth, int parentHeight) { 
     super.initialize(width, height, parentWidth, parentHeight); 
    } 

    @Override 
    public boolean willChangeBounds() { 
     return true; 
    } 
} 

ResizeAnimation resizeAnimation = new ResizeAnimation(view, MATCH_PARENT, false); 
resizeAnimation.setDuration(500); 
view.startAnimation(resizeAnimation); 

答えて

0

あなたが目標高さとして(-1ある値)View.MATCH_PARENTを渡しているので、あなたのアニメーションが動作しません。あなたは本当のターゲットの高さを渡す必要が-1(0xffffffffの)

int型MATCH_PARENT [...] 定数値:文書を引用。あなたはそれがレンダリングされた後、親のレイアウトで将来の目標の高さを測定することができます(私はあなたのためにViewTreeObserver.onGlobalLayout()をお勧めします)。

関連する問題