当用户滚动列表时,我正在尝试隐藏或显示我的工具栏.要做到这一点,我正在使用翻译,但会出现一个空格而不是我的actionBar.如果我使用setVisibility(View.GONE),动画期间将出现空白区域,并在完成时隐藏,这很难看.
Here is a short video of my issue
以下是我的动画制作方法(来自Google I / O应用程序):
public void showToolbar(boolean show){ if (show) { toolbar.animate() .translationY(0) .alpha(1) .setDuration(HEADER_HIDE_ANIM_DURATION) .setInterpolator(new DecelerateInterpolator()); } else { toolbar.animate() .translationY(-toolbar.getBottom()) .alpha(0) .setDuration(HEADER_HIDE_ANIM_DURATION) .setInterpolator(new DecelerateInterpolator()); } }
@H_404_12@这是我的布局:
@H_404_12@ 还有我的工具栏
@H_404_12@
最佳答案
您需要为容器设置动画,而不是工具栏.
试试这个:
RelativeLayout mainContent = (RelativeLayout) findById(R.id.mainContent); public void showToolbar(boolean show){ if (show) { mainContent.animate() .translationY(0) .alpha(1) .setDuration(HEADER_HIDE_ANIM_DURATION) .setInterpolator(new DecelerateInterpolator()); } else { mainContent.animate() .translationY(-toolbar.getBottom()) .alpha(0) .setDuration(HEADER_HIDE_ANIM_DURATION) .setInterpolator(new DecelerateInterpolator()); } }
@H_404_12@它对我有用;)
如果要使用工具栏移动片段,则需要为片段设置动画,而不仅仅是栏.