作者:追逐-晨曦 | 来源:互联网 | 2023-05-23 13:25
在我的应用程序中,我有RelativeLayout
任何小部件,进入布局,我想通过xml动画向上移动.RelativeLayout
可见性是GONE
必须GONE
再次设置可见性并将其移动到上方.
我的问题是这个,再次设置visibilty GONE
移动动画不工作和改变visibilty后VISIBLE
,RelativeLayout
可以显示,但只有那个孩子们向上移动,我想RelativeLayout
与所有chilss移动到顶部.如何解决这个问题?
XML动画:
动画代码:
animMoveUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation_move_up);
uiFiller.toolbarLinearlayoutIcons.setVisibility(View.VISIBLE);
uiFiller.toolbarLinearlayoutIcons.startAnimation(animMoveUp);
我的布局:
在这个布局中我想移动toolbarLinearlayoutIcons
id
1> Kastriot Dre..:
您可以使用xml中的1行将其放在父布局上
android:animateLayoutChanges="true"
2> 小智..:
使用以下方法展开和折叠所需的视图:
public void expand(final View v) {
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final int targtetHeight = v.getMeasuredHeight();
if (v.isShown()) {
collapse(v);
} else {
v.getLayoutParams().height = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
: (int) (targtetHeight * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration((int) (targtetHeight + 500));
v.startAnimation(a);
}
}
public void collapse(final View v) {
final int initialHeight = v.getMeasuredHeight();
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
if (interpolatedTime == 1) {
v.setVisibility(View.GONE);
} else {
v.getLayoutParams().height = initialHeight
- (int) (initialHeight * interpolatedTime);
v.requestLayout();
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration((int) (v.getLayoutParams().height + 500));
v.startAnimation(a);
}