Java 显示AlertDialog时,测量(…)宽度和高度的自定义视图为0
我的应用程序由一个Java 显示AlertDialog时,测量(…)宽度和高度的自定义视图为0,java,android,view,bitmap,android-alertdialog,Java,Android,View,Bitmap,Android Alertdialog,我的应用程序由一个MapActivity组成,它加载一个XML视图(map\u布局),其中包含一个MapView和一个CustomView,后者扩展了ImageView 我使用以下代码设置我的MapActivity: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_layout);
MapActivity
组成,它加载一个XML视图(map\u布局),其中包含一个MapView
和一个CustomView
,后者扩展了ImageView
我使用以下代码设置我的
MapActivity
:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
initialise();
}
然后在初始化中,我像往常一样使用findViewById(…)
从XML文件中检索MapView
和CustomView
在my
CustomView的onMeasure(…)
函数中,我使用this.getWidth()
和this.getHeight()
获取其尺寸,从而返回正确的结果
然后在我的initialise()
现在的问题是,myCustomView的onMeasure(…)
函数不再正常工作,this.getWidth()
和this.getHeight()
如果显示AlertDialog
则都返回0
为什么会这样
提前感谢您的帮助,如果我的问题不清楚,我会在有机会时编辑它以添加完整的代码。好的,出于某种原因,我需要在onLayout()
中获得高度和宽度,而不是onMeasure()