如何翻译视图,但保持其原始起始位置 [英] How to translate a view, but keep it's original starting position
问题描述
我正在对视图进行动画处理,以便在出现键盘时隐藏底部的导航栏.
I am animating a view so that a bottom navigation bar is hidden when the keyboard appears.
我的问题是我可以平移底部导航栏,而主要的消息区域"可以跟随它,但是在消息区域"的顶部会形成一个间隙.有没有一种翻译方法,但可以使消息区域"的顶部与操作栏对齐?
My issue is that I can translate away the bottom navigation bar and the main 'message area' can follow it, but at the top of the 'message area' a gap forms. Is there a way to translate, but keep the top of the 'message area' aligned with the action bar?
以下是动画和正在形成的缝隙的一个示例:
Here is an example of the animation and the gap that is forming:
我的动画代码如下:
if (lowerNavigationBar.getVisibility() == View.VISIBLE) {
lowerNavigationBar.animate()
.translationY(lowerNavigationBar.getHeight()).setDuration(1000).start();
viewPager.animate()
.translationY(lowerNavigationBar.getHeight()).setDuration(1000).start();
lowerNavigationBar.setVisibility(View.INVISIBLE);
}
else{
lowerNavigationBar.setVisibility(View.VISIBLE);
lowerNavigationBar.animate()
.translationY(0).setDuration(1000).start();
viewPager.animate()
.translationY(0).setDuration(1000).start();
}
推荐答案
I ended up testing two things, the first from this stack overflow answer which adjusts the actual height of the layout, which did work, but wasn't as smooth as I would have liked.
第二个是此库,它使用ValueAnimators并提供了更加流畅的动画以及更多功能.我最终还是坚持使用了这个库,因为它在视觉上提供了更好的结果,并且易于定制.
The second being this library which uses ValueAnimators and provided a much smoother animation as well as further functionality. I ended up sticking with this library as it gives much better results visually and is simple to customise.
这篇关于如何翻译视图,但保持其原始起始位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!