有一段android代码不是很懂。求指教(下拉刷新时求Head的高度的一个方法)
privatevoidmeasureView(Viewchild){//TODOAuto-generatedmethodstubViewGroup.LayoutParam...
private void measureView(View child) {
// TODO Auto-generated method stub
ViewGroup.LayoutParams p=child.getLayoutParams();
if(p==null)
{
p=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
int childWidthSpec=ViewGroup.getChildMeasureSpec(0, 0+0, p.width);
int lheight=p.height;
int childHeightSpec;
if(lheight>0)
{
childHeightSpec=MeasureSpec.makeMeasureSpec(lheight,MeasureSpec.EXACTLY);
}
else
{
childHeightSpec=MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
child.measure(childWidthSpec, childHeightSpec);
}
然后调用子布局的getMeasuredHeight()方法 可以获得子布局的具体高度 。 展开
// TODO Auto-generated method stub
ViewGroup.LayoutParams p=child.getLayoutParams();
if(p==null)
{
p=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
int childWidthSpec=ViewGroup.getChildMeasureSpec(0, 0+0, p.width);
int lheight=p.height;
int childHeightSpec;
if(lheight>0)
{
childHeightSpec=MeasureSpec.makeMeasureSpec(lheight,MeasureSpec.EXACTLY);
}
else
{
childHeightSpec=MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
child.measure(childWidthSpec, childHeightSpec);
}
然后调用子布局的getMeasuredHeight()方法 可以获得子布局的具体高度 。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询