2016-02-03 100 views
1

我的FrameLayout的小孩MapBoxViewMapBox的Android佈局無效時,父視圖改變大小

<?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> 

更改父視圖的大小,但MapView類沒有更新佈局

我嘗試打電話requsetLayout()嘗試invalidateLayout() - 沒有效果。

enter image description here

enter image description here

回答

1

你有沒有嘗試過的LinearLayout內包裝你的FrameLayout所以它看起來是這樣的:

<?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> 

除非您打算加入的對象,如在頂部的按鈕然而,mapView佈局,FrameLayout可以被移除。如果在運行時更改對象或大小的位置,則使用android.support.design.widget.CoordinatorLayout而不是FrameLayout也可能有所幫助。

+0

這不起作用。地圖還在削減。 –

+0

如果你仍然有這個問題,我可以幫助你發佈你的java代碼,改變佈局。現在用你發佈的代碼,我沒有看到任何問題。 – cammace

相關問題