我的目的是创建一个不可见的LinearLayout,在点击特定按钮时带有动画效果出现。为了实现这一点,我将默认高度设置为WRAP_CONTENT,在应用程序启动时获取高度,将高度设置为0,并在单击按钮时开始动画。以下是代码:
linearLayout.post(new Runnable() {
@Override
public void run(){
height = linearLayout.getMeasuredHeight();
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 0));
}
});
findViewById(R.id.btnOperator).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation ani = new ShowAnim(linearLayout, height/* target layout height */);
ani.setDuration(1000/* animation time */);
linearLayout.startAnimation(ani);
}
});
这个工作得很好,但我想改变一下。我希望默认高度为0,然后计算WRAP_CONTENT的高度,并将其传递给:
Animation ani = new ShowAnim(linearLayout, height/* target layout height */);
我该怎么做?我搜索了但没有找到任何东西。
measure
方法接受的是MeasureSpec
而不是LayoutParam的宽度。 来源:https://developer.android.com/reference/android/view/View.MeasureSpec - undefined