简体   繁体   English

当父视图更改大小时,MapBox Android使布局无效

[英]MapBox Android invalidate layout when parent view change size

I have frameLayout with a child MapBoxView 我有一个带有子MapBoxView的frameLayout

<?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 我更改了父视图的大小,但MapView并未更新布局

I try call requsetLayout(), try invalidateLayout() - no effect. 我尝试调用requsetLayout(),尝试invalidateLayout()-无效。

在此处输入图片说明

在此处输入图片说明

Have you tried wrapping your FrameLayout within a LinearLayout so it looks something like this: 您是否尝试过将FrameLayout包装在LinearLayout中,所以看起来像这样:

<?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. 除非您计划在mapView布局顶部添加诸如按钮之类的对象,否则可以删除FrameLayout。 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. 如果您在运行时更改对象或大小的位置,那么使用android.support.design.widget.CoordinatorLayout而不是FrameLayout可能也会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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