I was developing a customized view when I encountered this problem. In the XML I set the layout_width
& layout_height
with fixed value 100dp
. But in onMeaure()
method I got widthMeasureSpec
with measureMode EXACTLY
, but heightMeasureSpec
with measureMode AT_MOST
. What's more weird is that they come with different size value. Here's the XML and related code fragment:
CODE:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthMeasureMode = MeasureSpec.getMode(widthMeasureSpec);
int widthMeasureSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMeasureMode = MeasureSpec.getMode(heightMeasureSpec);
int heightMeasureSize = MeasureSpec.getSize(heightMeasureSpec);
}
XML:
<com.my.view
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@color/theme"
app:contentSizeRatio="50%"
app:imageSource="@drawable/ic_logo_white_48"/>