问题:

今天在布局文件里面直接拉一个MapView,然后在java文件里面

mShowMapView = (MapView) findViewById(R.id.mvMachine);
发现只要一调用就出错
后来在xml文件中使用Map_container来作为MapView容器可一解决出错问题
才疏学浅,原理记录一下
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.4"
    android:orientation="vertical">

    <com.chinamobile.iot.onenet.sdksample.view.MapContainer
        android:id="@+id/map_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp">

        <com.amap.api.maps2d.MapView
            android:id="@+id/mvMachine"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </com.amap.api.maps2d.MapView>
    </com.chinamobile.iot.onenet.sdksample.view.MapContainer>
</LinearLayout>

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐