1.我需要做一个点击按钮从下方平移上来一个按钮的动画,我选择的是使用属性动画去做,我一开始是直接将这个按钮隐藏掉了,然后计算这个按钮的高度使用属性动画让他从底部平移上来,然而却失效了。
recyclerCoverFlow.setVisibility(View.VISIBLE);
ObjectAnimator bacrkgroundAnimatorBottom = ObjectAnimator.ofFloat(recyclerCoverFlow,"translationY",height,0);
bacrkgroundAnimatorBottom.setDuration(500);
bacrkgroundAnimatorBottom.start();
原因:当空间隐藏时是无法获取到控件的高度的,还有当onCreate执行时,也是无法获取控件的高度的,
解决办法:当控件测量完毕时在将其隐藏
ViewTreeObserver vto = recyclerCoverFlow.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
recyclerCoverFlow.getViewTreeObserver().removeGlobalOnLayoutListener(this);
height = recyclerCoverFlow.getHeight();
recyclerCoverFlow.getWidth();
recyclerCoverFlow.setVisibility(View.GONE);
}
});