2016-02-26 40 views
0

返回不同的值,我有一个自定义视图,它有几个孩子的意见,fabMenu就是其中之一ImageView的,我写了下面的代码在onMeasure()方法子视图getMeasureWidth在不同的时间

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    measureChild(fabMenu, widthMeasureSpec, heightMeasureSpec); 
    int width = fabMenu.getMeasuredWidth(); 
    int height = fabMenu.getMeasuredHeight(); 
    Log.d(TAG, "onMeasure: width " + fabMenu.getMeasuredWidth() + " height " + fabMenu.getMeasuredHeight()); 
... 
} 

但每次日志显示不同的值

+0

日志传递'widthMeasureSpec'和'heightMeasureSpec'参数和观看的logcat,他们最有可能每次都不同'onMeasure'被称为 – pskink

+0

是,widthMeasureSpec和heightMeasureSpec参数发生改变,但是怎么过来?我不知道 。 – Zhli

+0

仔细阅读'MeasureSpec'文档以了解'onMeasure'参数是如何编码的 – pskink

回答

0

家伙〜

我终于“解决”问题。

我把我的自定义视图放在一个RelativeLayout之前,但现在我把它放到一个FrameLayout(然后把FrameLayout放到父视图 - RelativeLayout中)。

然后一切正常〜

相关问题