如何从非 UI 线程中膨胀 MapView
我的应用程序使用 HoneyComb 片段,其中我的左侧面板有列表视图,右侧面板有一个带有一些 TextView 的 MapView。最初我在 map_fragment_right_side.xml 中编写了地图视图,这导致屏幕长时间冻结,所以我决定膨胀地图在运行时在 AsyncTask 中查看是徒劳的。代码是这样的
class LoadMapTask extends AsyncTask<String, Void, Boolean>
{
MapView inflatedMapView = null;
@Override
protected void onPreExecute() {
progressbar.setVisibility( View.VISIBLE );
}
@Override
protected Boolean doInBackground(String... params)
{
try{
inflatedMapView = new MapView(getActivity(),getActivity().getResources().getString(R.string.mapkey));
addMapViewhere.addView(inflatedMapView);
inflatedMapView.getController().setCenter(getPoint(Double.valueOf(latitude),Double.valueOf(longitude)));
inflatedMapView.getController().setZoom(17);
inflatedMapView.setBuiltInZoomControls(true);
sites=new SitesOverlay();
inflatedMapView.getOverlays().clear();
inflatedMapView.getOverlays().add(sites);
}catch (Exception e) {
e.printStackTrace();
}
return true;
}
@Override
protected void onPostExecute(Boolean res)
{
if( progressbar != null )
{
progressbar.setVisibility( View.GONE );
}
}
}
我怀疑是否可以从非 UI 线程膨胀地图视图。如果有人建议我,我会很高兴正确的方法是这样做。我不希望屏幕在地图加载之前冻结。
谢谢,
加内什
My app uses HoneyComb fragments where my left side panel has listview and right side panel has a MapView with some TextViews.Initially i wrote map view in the map_fragment_right_side.xml which resulted in freezing the screen for long time ,so I decided to inflate the map view at runtime in an AsyncTask in vain .The code goes like this
class LoadMapTask extends AsyncTask<String, Void, Boolean>
{
MapView inflatedMapView = null;
@Override
protected void onPreExecute() {
progressbar.setVisibility( View.VISIBLE );
}
@Override
protected Boolean doInBackground(String... params)
{
try{
inflatedMapView = new MapView(getActivity(),getActivity().getResources().getString(R.string.mapkey));
addMapViewhere.addView(inflatedMapView);
inflatedMapView.getController().setCenter(getPoint(Double.valueOf(latitude),Double.valueOf(longitude)));
inflatedMapView.getController().setZoom(17);
inflatedMapView.setBuiltInZoomControls(true);
sites=new SitesOverlay();
inflatedMapView.getOverlays().clear();
inflatedMapView.getOverlays().add(sites);
}catch (Exception e) {
e.printStackTrace();
}
return true;
}
@Override
protected void onPostExecute(Boolean res)
{
if( progressbar != null )
{
progressbar.setVisibility( View.GONE );
}
}
}
I doubt whether its possible to inflate map view from non-UI thread .I will be glad if someone suggest me the right way to do this.I don't want the screen to freeze until map gets loaded.
thanks,
ganesh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
onPreExecute()
或在onPostExecute()
中对其进行充气Inflate it from
onPreExecute()
or inonPostExecute()