bottomFrameAnimationOut = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.ABSOLUTE, -205, TranslateAnimation.ABSOLUTE, 0);
原来这里的每一个参数都是相对于当前view的值。
如果你想点击一个按钮然后把一个view从一个地方移到另一个地方的话。
mailboxHeaderBar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mailboxHeaderBar.getLayoutParams();
int bottomMargin = layoutParams.bottomMargin;
if (bottomMargin < 0) {
mailboxHeaderBar.startAnimation(bottomFrameAnimationIn);
layoutParams.bottomMargin = 0;
}else{
mailboxHeaderBar.startAnimation(bottomFrameAnimationOut);
layoutParams.bottomMargin = -205;
}
mailboxHeaderBar.setLayoutParams(layoutParams);
}
});
其实在你startAnimation的时候View的位置已经变了。 Animation里面的参数值是需要相对你移动view之后的值。 有点晕 fuck