2015-11-26 170 views
1

我有一个滚动视图,其中有一个相对布局,其中包含顶部灵活大小的内容以及其下的地图视图。如果整个内容的高度小于屏幕视图端口(滚动视图),我希望地图视图填充下面的剩余空间。如果整个内容大于屏幕视图端口,那么我希望地图视图具有至少一定的高度。这是我所做的一个剥离版本。地图视图没有完全加载

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/flexContent" 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:layout_alignParentTop="true" 
      android:background="#086dd9" 
      android:gravity="center" 
      android:text="Flexible content here" 
      android:textColor="@android:color/white" 
      android:textSize="22sp" /> 

     <com.google.android.gms.maps.MapView 
      android:id="@+id/mapView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_below="@id/flexContent" 
      android:background="#f73f3f" 
      android:minHeight="120dp" 
      map:mapType="normal" 
      tools:ignore="MissingPrefix" /> 
    </RelativeLayout> 


</ScrollView> 

它将按预期工作时的全部内容的高度比屏幕视口的高度(滚动视图的高度)小。但是,如果不是,则除非地图不加载到地图视图的全高,否则一切正常。请把下面

含量小的看图片比滚动视图 enter image description here

含量比滚动型

enter image description here

更大正如你可以在第二张图片看到,地图视图本身是尊重在布局中设置的minHeight 120dp约束(我将地图视图的背景设为红色),但实际地图是没有加载到它的全部高度。

这怎么解决?

+0

看看这个:http://stackoverflow.com/questions/29956014/why-should-we-use-xml-layouts – Nanoc

回答

1

我通过将MapView包装在LinearLayout中解决了上述问题。我的最终布局现在看起来与此类似。希望它可以帮助任何人在未来:)

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/flexContent" 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:layout_alignParentTop="true" 
      android:background="#086dd9" 
      android:gravity="center" 
      android:text="Flexible content here" 
      android:textColor="@android:color/white" 
      android:textSize="22sp" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_below="@id/flexContent" 
      android:orientation="vertical" 
      android:minHeight="120dp"> 

      <com.google.android.gms.maps.MapView 
       android:id="@+id/mapView" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:background="#f73f3f" 
       map:mapType="normal" 
       tools:ignore="MissingPrefix" /> 

     </LinearLayout> 

    </RelativeLayout> 

</ScrollView> 
+0

在我的情况下,帮助http://stackoverflow.com/questions/32908988/android-map-loading-very-slow-not-loading-at-all-in-started-activity-until-click 以防万一这不利于任何人。 –