2

我正在为滑雪者和单板滑雪者开发一个 Android 应用程序,它应该将用户从一个点导航到另一个点。

为了显示地图,我使用的是 Mapsforge-Version 0.4.0。

在地图上,我添加了一些图层,现在我想添加一个 Imagebutton,但所有尝试都失败了。您是否有一些想法如何在没有 Xml 文件的情况下做到这一点?

我是新手,这是我的第一个问题,所以如果我忘记了一些信息,请告诉我。

4

1 回答 1

3

第 1 步:避免将内容视图设置为 mapView

   // setContentView(mapView);


第 2 步:将您的按钮添加到线性布局
只需将您的线性布局添加到相对布局

<RelativeLayout
    android:id="@+id/rlMap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:id="@+id/llControls"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button" />

    </LinearLayout>

</RelativeLayout>

第 3 步:找到您的 RelativeLayout 并将您的 mapView 对象添加到其中

RelativeLayout rlMap = (RelativeLayout) findViewById(R.id.rlMap);
rlMap.addView(mapView,0);
于 2014-10-02T08:07:14.050 回答