简体   繁体   中英

MapBox Android invalidate layout when parent view change size

I have frameLayout with a child MapBoxView

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto">

    <com.mapbox.mapboxsdk.views.MapView
        android:id="@+id/mapBoxMapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        mapbox:access_token="@string/accessTokenMapBox"/>

</FrameLayout>

I change size of parent view, but MapView did not update layout

I try call requsetLayout(), try invalidateLayout() - no effect.

在此处输入图片说明

在此处输入图片说明

Have you tried wrapping your FrameLayout within a LinearLayout so it looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto"
    tools:context="com.mycompany.myfirstglapp.MainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:mapbox="http://schemas.android.com/apk/res-auto">

        <com.mapbox.mapboxsdk.views.MapView
            android:id="@+id/mapBoxMapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            mapbox:access_token="@string/accessTokenMapBox"/>

    </FrameLayout>

Unless you plan on adding objects such as a button on top of the mapView layout, the FrameLayout can be removed however. If you are changing a position of a object or size during runtime, using android.support.design.widget.CoordinatorLayout instead of FrameLayout might help as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM