我正在我的MapActivity.java中创建一个OSMdroid mapview,我想添加按钮&弹出窗口 – 我只知道这是如何在.xml中完成的,但由于这个MapView没有使用任何.xml,我很困惑如何在我的java代码中放置(图像)按钮.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Setup base map
final RelativeLayout rl = new RelativeLayout(this);
CloudmadeUtil.retrieveCloudmadeKey(getApplicationContext());
final MapView osmv = new MapView(this,256);
myMapController = osmv.getController();
rl.addView(osmv,new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
osmv.setBuiltInZoomControls(true);
osmv.setMultiTouchControls(true);
myLocationoverlay = new MyLocationOverlay(this,osmv);
//*snip* setup of map,mapcontrollers,tiles etc...
osmv.getOverlays().add(tilesOverlay);
osmv.getOverlays().add(myLocationoverlay);
this.setContentView(rl);
}
编辑:
我说的是一个按钮
最佳答案
感谢MH的提示,我发现如何以编程方式将ImageButton添加到我的代码中,如下所示:
ImageButton goto_location = new ImageButton(this);
goto_location.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showMylocation();
}
});
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(40,40);
params.rightMargin = 10;
params.topMargin = 10;
rl.addView(goto_location,params);