我做了一个自定义视图。如果我将视图添加到布局XML文件中,并将高度设置为fill_parent "specSize“,则返回0。为什么?
代码:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredHeight = 90;
int specMode = MeasureSpec.getMode(heightMeasureSpec);
int specSize = MeasureSpec.getSize(MeasureSpec.getMode(heightMeasureSpec));
if(specMode != MeasureSpec.UNSPECIFIED){
measuredHeight = specSize;
}
setMeasuredDimension(60, measuredHeight);
}有人知道怎样才能得到fill_parent的高度吗
发布于 2010-05-13 21:48:03
你不需要在“getSize”的调用中调用MeasureSpec.getMode。测量规范的全部思想是将测量方法(称为规范)和相关的大小结合起来。有关MeasureSpec.makeMeasureSpec method.So的正确代码,请参阅文档,如下所示:
int widthSpec = MeasureSpec.getMode(widthMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);发布于 2011-11-24 04:28:30
正确的代码是:
int specMode = MeasureSpec.getMode(heightMeasureSpec); ----This was already correct
int specSize = MeasureSpec.getSize(heightMeasureSpec); ----This is corrected.https://stackoverflow.com/questions/2826942
复制相似问题