我遇到了一个问题,我有一个标题 View ,我想将其转换为可见性——使用转换动画——它位于主内容 View 的正上方。为了说明我的意思,请看下图。蓝色部分是标题,橙色部分是主要内容。
示例代码
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -rlInfoBar.getHeight());
animation.setFillAfter(true);
animation.setDuration(10000);
animation.setAnimationListener(new TranslateAnimation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
rvItems.startAnimation(animation);
rlInfoBar.startAnimation(animation);
当我翻译蓝色部分时,即使主要部分被声明为“android:layout_below="@+id/",它仍然保留在原位。我的想法是然后将它们都翻译,但是,在这样做时主要内容向上移动,但屏幕底部也向上移动,显示父 View 的背景。如何解决这个问题?我是否必须平移两个 View 并拉伸(stretch)主要内容 View 或以某种方式将主要内容 View 锚定到底部屏幕的?
翻译两个 View 的结果
最佳答案
Do I have to translate both views plus stretch the main content view or somehow anchor the main content view to the bottom of the screen?
好吧,如果你不拉伸(stretch)主要内容 View
然后将其锚定到底部将导致在标题 View
出现时顶部出现间隙向上移动。所以我认为您需要一组动画(缩放和平移)。
或者您使用 Transition framework ,在这种情况下,ChangeBounds
转换将为两个 View
View sceneRoot = <someViewGroupContainingBothViews>;
TransitionManager.beginDelayedTransition(sceneRoot, new ChangeBounds());
rlInfoBar.setY(<newY_CoordinateOfHeaderView>);
关于android - 在具有位置依赖性的 View 上转换动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49212119/