public void open() { if (!isOpen) { isOpen = true; for (int i = 0; i < getChildCount() - 1; i++) { View child = getChildAt(i); child.setVisibility(VISIBLE); } mPosY = 0; for (OnToggleTouchListener l : listeners) { l.onStartOpen(expandHeight, originalHeight); } int childCount = getChildCount(); for (int i = childCount - 2; i > -1; i--) { View child = getChildAt(i); View preChild = getChildAt(i + 1); int preHeight = preChild.getMeasuredHeight(); OpenViewAnimator animator = new OpenViewAnimator(mTop, mPosY + preHeight, i); animator.animate(child); Log.e("animate open", "invoked"); if (i == 0) { animator.addAnimatorListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { for (OnToggleTouchListener l : listeners) { l.onOpen(); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); } mPosY = mPosY + preHeight; } } }
public void close() { if (isOpen) { isOpen = false; for (OnToggleTouchListener l : listeners) { l.onStartClose(expandHeight, originalHeight); } int childCount = getChildCount(); for (int i = 0; i < childCount - 1; i++) { View child = getChildAt(i); View preChild = getChildAt(i + 1); CloseViewAnimator animator = new CloseViewAnimator(mPosY, mTop, i); animator.animate(child); Log.e("animate open", "invoked"); if (i == 0) { animator.addAnimatorListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { for (int i = 0; i < getChildCount() - 1; i++) { View child = getChildAt(i); child.setVisibility(INVISIBLE); } for (OnToggleTouchListener l : listeners) { l.onClosed(); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); } mPosY = mPosY - preChild.getMeasuredHeight(); } } }