在具有位置依赖性的视图上转换动画
Translate animation on views with position dependencies
我 运行 遇到一个问题,我有一个 header 视图,我想将其转换为可见性——使用转换动画——它位于主视图的正上方内容视图。为了说明我的意思,请看下图。蓝色部分是header,橙色部分是主要内容
示例代码
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/" 它仍然保留在原位。我的想法是然后将它们都翻译,但是,这样做时主要部分内容向上移动,但屏幕底部也向上移动,显示 parent 视图的背景。如何解决这个问题?我是否必须平移两个视图并拉伸主要内容视图或以某种方式锚定主要内容内容视图到屏幕底部?
两个视图的翻译结果
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?
好吧,如果你不拉伸主要内容 View
然后将其锚定到底部,一旦 header View
向上移动。所以我认为您需要一组动画(缩放和平移)。
或者您使用 Transition framework,在这种情况下,ChangeBounds
过渡将为 View
和
完成工作
View sceneRoot = <someViewGroupContainingBothViews>;
TransitionManager.beginDelayedTransition(sceneRoot, new ChangeBounds());
rlInfoBar.setY(<newY_CoordinateOfHeaderView>);
我 运行 遇到一个问题,我有一个 header 视图,我想将其转换为可见性——使用转换动画——它位于主视图的正上方内容视图。为了说明我的意思,请看下图。蓝色部分是header,橙色部分是主要内容
示例代码
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/" 它仍然保留在原位。我的想法是然后将它们都翻译,但是,这样做时主要部分内容向上移动,但屏幕底部也向上移动,显示 parent 视图的背景。如何解决这个问题?我是否必须平移两个视图并拉伸主要内容视图或以某种方式锚定主要内容内容视图到屏幕底部?
两个视图的翻译结果
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?
好吧,如果你不拉伸主要内容 View
然后将其锚定到底部,一旦 header View
向上移动。所以我认为您需要一组动画(缩放和平移)。
或者您使用 Transition framework,在这种情况下,ChangeBounds
过渡将为 View
和
View sceneRoot = <someViewGroupContainingBothViews>;
TransitionManager.beginDelayedTransition(sceneRoot, new ChangeBounds());
rlInfoBar.setY(<newY_CoordinateOfHeaderView>);