【发布时间】:2014-04-29 20:28:54
【问题描述】:
我有一个想要设置动画的 TextView。 最初,TextView 设置为 visibility=GONE,高度为 wrap_content。当用户执行特定操作时,TextView 设置为可见。几秒钟后,我想将 TextView 的高度从它的 wrap_content 高度设置为 0dp。我的工作没有任何问题。当动画结束时,我的问题就来了。动画完成后,我将 TextView 设置回 visibility=GONE 并尝试将 TextView 的高度重置为 wrap_content 但高度似乎没有改变。
我尝试将 TextView 的布局参数设置回 wrap_content 的高度,然后使 TextView 无效,但这不起作用。
知道该怎么做吗?
这是我目前制作动画的方式:
Animation slideUp = new Animation() {
{
setDuration(1000);
setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { }
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationEnd(Animation animation) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mTxtTimerSet.getLayoutParams();
lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
mTxtTimerSet.setVisibility(View.INVISIBLE);
mTxtTimerSet.setLayoutParams(lp);
mTxtTimerSet.invalidate();
mTxtTimerSet.setVisibility(View.GONE);
}
});
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mTxtTimerSet.getLayoutParams();
lp.height = mTxtTimerSet.getHeight() - ((int) (mTxtTimerSet.getHeight() * interpolatedTime));
mTxtTimerSet.setLayoutParams(lp);
}
};
mTxtTimerSet.startAnimation(slideUp);
谢谢
【问题讨论】: