Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在XML中,宽度和高度都固定时,OnMeasure获取错误值_Android_Xml_Onmeasure - Fatal编程技术网

Android 在XML中,宽度和高度都固定时,OnMeasure获取错误值

Android 在XML中,宽度和高度都固定时,OnMeasure获取错误值,android,xml,onmeasure,Android,Xml,Onmeasure,当我遇到这个问题时,我正在开发一个定制视图。在XML中,我使用固定值100dp设置layout\u宽度和layout\u高度。但是在onMeaure()方法中,我用measureMode精确地得到了widthmasurespec,但用measureMode得到的是heightMeasureSpec。更奇怪的是,它们的大小和价值不同。以下是XML和相关代码片段: 代码: XML: protected void onMeasure(int widthMeasureSpec, int heigh

当我遇到这个问题时,我正在开发一个定制视图。在XML中,我使用固定值
100dp
设置
layout\u宽度
layout\u高度
。但是在
onMeaure()
方法中,我用measureMode
精确地得到了
widthmasurespec
,但用measureMode
得到的是
heightMeasureSpec
。更奇怪的是,它们的大小和价值不同。以下是XML和相关代码片段:

代码:

XML:


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);
}
<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"/>