我正在尝试创建一个动画,其中 LinearLayout
升起 (TranslateAnimation
),并且 LinearLayout
中的 fragment 变为另一个 fragment (淡入/淡出)。
我设法让它完美地工作,但唯一的问题是 LinearLayout
的布局保持在相同的位置(尽管“填充”确实上升并保持这种状态)。
这导致我无法单击 fragment 内 LinearLayout
先前位置之外的任何 View 。
如何使布局“向上移动”以匹配填充的新位置?
当前动画逻辑
final int AmountToMove = -(desiredHeight - mLL.getHeight());
Animation animation = new TranslateAnimation(0, 0, 0, AmountToMove);
animation.setDuration(1000);
animation.setInterpolator(this,
android.R.anim.anticipate_overshoot_interpolator);
animation.setFillAfter(true);
if(CARD_STATE == 0)
mLL.startAnimation(animation);
具有布局边界的图像
编辑 1:触发动画之前的布局图像
编辑2:再次尝试达到预期效果
animation.setAnimationListener(new TranslateAnimation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
LinearLayout.LayoutParams Lp = (LinearLayout.LayoutParams) mLL.getLayoutParams();
Lp.bottomMargin += AmountToMove;
mLL.setLayoutParams(Lp);
}
});
这也行不通。
最佳答案
如果您需要 View 在动画完成后消失,则只需在动画完成时将可见性设置为消失即可:
animation.setAnimationListener(new TranslateAnimation.AnimationListener()
{
@Override
public void onAnimationStart(Animation animation) { }
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationEnd(Animation animation)
{
mLL.setVisibility(View.GONE);
}
});
如果您需要让它移动一点,请尝试在动画完成后调整其布局参数(边距),而不仅仅是更改可见性。
关于java - 平移动画会导致 View 的填充位置发生变化,但不会导致布局发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24675635/