【发布时间】:2012-01-11 21:50:02
【问题描述】:
我的应用程序包含一个 MapActivity,它加载一个 XML 视图 (map_layout),其中包含一个 MapView 和一个扩展 ImageView 的 CustomView。
我使用以下代码设置我的MapActivity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
initialise();
}
然后在初始化时,我像往常一样使用 findViewById(...) 从 XML 文件中检索 MapView 和 CustomView。
在我的CustomView 的onMeasure(...) 函数中,我使用this.getWidth() 和this.getHeight() 来获取它的尺寸,这会返回正确的结果。
然后在我的initialise() 代码中,我决定检查 GPS 是否已启用(使用类似于此处第一个答案的代码:How do I find out if the GPS of an Android device is enabled),如果 GPS 已禁用,则显示 AlertDialog。
现在的问题是我的CustomView 的onMeasure(...) 函数不再正常工作,如果AlertDialog 显示,this.getWidth() 和this.getHeight() 都返回0。
为什么会这样?
提前感谢您的帮助,如果我的问题不清楚,我会在有机会时对其进行编辑以添加完整的代码。
【问题讨论】:
标签: java android view bitmap android-alertdialog