我正在使用TranslateAnimation为视图设置动画,以实现下拉视图动画。我面临的问题是动画完成后容器的大小不会增加。

请检查图片和代码段代码:

TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f, top, top + px);
animation.initialize(mDropDownLayout.getWidth(),mDropDownLayout.getHeight(), parentLayout.getWidth(), parentLayout.getHeight());
animation.setDuration(2000);
animation.setFillEnabled(true);
animation.setFillBefore(true);
mDropDownLayout.startAnimation(animation);


我试图实现的结果是,随着动画视图的平移,容器的高度应随着的增加而增加。

更新:此外,动画视图仅在视觉上移动,而不在结构上移动。

最佳答案

我不确定这种方式,请尝试一次。

RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));


将此layoutParams设置为您的relativeLayout

然后您可以根据自己的要求更改宽度/高度,如下所示

layoutParams.width = 10;
layoutParams.height = 10;

07-24 09:47
查看更多