如何获得在XML中定义为wrap_content的可见性和高度已消失的视图的高度? [英] How get height of the a view with gone visibility and height defined as wrap_content in xml?
本文介绍了如何获得在XML中定义为wrap_content的可见性和高度已消失的视图的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有Viewibility = gone和height = wrap_content的ListView,并且我需要它的高度才能制作展开动画.
I have a ListView with visibility=gone and height=wrap_content, and i need its height to can make an animation of expand.
我已经尝试过了:
view.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = view.getMeasuredHeight();
和
v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
int height = view.getMeasuredHeight();
和
v.measure(View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED));
int height = view.getMeasuredHeight();
但是它给了我一个较小的价值.
But it returned me a lesser value.
我正在尝试在onResume之后执行此操作.
I am trying to do this after onResume.
推荐答案
我发现的唯一方法是从可见的标头视图的宽度设置我的视图的宽度,然后下面的代码为我返回了正确的值./p>
The only way that i found was setting the width of the my view from width of a visible header view, then the below code returned me the right value.
int widthSpec = MeasureSpec.makeMeasureSpec(headerView.getWidth(), MeasureSpec.EXACTLY);
int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
v.measure(widthSpec, heightSpec);
int height = v.getMeasuredHeight();
这篇关于如何获得在XML中定义为wrap_content的可见性和高度已消失的视图的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文