【发布时间】:2019-02-05 07:56:07
【问题描述】:
我尝试使用动画更改我的 relativeLayout 宽度。我的目标是使用动画将 WRAP_CONTENT 宽度更改为 MATCH_PARENT。这是我的源代码
private void setWidthAnimation(View view, int currentHeight, int newHeight) {
ValueAnimator slideAnimator = ValueAnimator
.ofInt(currentHeight, newHeight)
.setDuration(1000);
slideAnimator.addUpdateListener(animation -> {
Integer value = (Integer) animation.getAnimatedValue();
view.getLayoutParams().width = value.intValue();
view.requestLayout();
});
AnimatorSet set = new AnimatorSet();
set.play(slideAnimator);
set.setInterpolator(new BounceInterpolator());
set.start();
view.setBackgroundColor(Color.RED);
}
我是这样调用这个方法的
if (isKeyBoardOpen)
setWidthAnimation(gifEditableLayout, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
else
setWidthAnimation(gifEditableLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
但是当我运行我的应用程序时,视图的宽度发生了变化,但没有动画。谁能解释我做错了什么? 谢谢
【问题讨论】:
标签: android android-layout android-animation