Mapview上的按钮

bir*_*git 5 java android openstreetmap android-layout osmdroid

我正在我的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);
}
Run Code Online (Sandbox Code Playgroud)

编辑:我说的是一个按钮

<ImageButton
    android:id="@+id/map_goto_location"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/goto_location"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" 
    android:id="@+id/goto_location" />
Run Code Online (Sandbox Code Playgroud)

bir*_*git 4

感谢 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);
Run Code Online (Sandbox Code Playgroud)

如果有人可以提示我一些关于自定义按钮和以编程方式添加 UI 元素的好教程/示例,我将非常高兴。