首页 文章

MapView不支持layout_height = wrap_content

提问于
浏览
0

我正在构建一个包含两个按钮和一个MapView的布局 . 按钮应放在MapView的上方和下方 . 我已经尝试了几种布局组合(相对,线性,帧......),但MapView不支持layout_height = wrap_content,除非我使用像layout_height =“200dp”这样的特定高度 .

显示tope按钮,但不显示底部按钮 . 下面是我的测试XML文件 .

有什么建议?

android:layout_width =“fill_parent”android:layout_height =“fill_parent”>

<Button     
    android:id="@+id/btn1" 
    android:layout_width="fill_parent"          
    android:layout_height="wrap_content"
    android:text="Button1" 
    android:background="#FF0000" />

<com.google.android.maps.MapView
    android:id="@+id/map1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:apiKey="my map key (removed for example)"
/>           

<Button     
    android:id="@+id/btn2" 
    android:layout_width="fill_parent"          
    android:layout_height="wrap_content"
    android:text="Button2"
    android:background="#00FF00" />

2 回答

  • 1

    我遇到了同样的问题(我的mapview是在两个布局而不是按钮之间),并用“height = 0dp”和“weight = 1”解决了这个问题,因此mapview会调整到上面和下面的布局 .

    <com.google.android.maps.MapView
      android:id="@+id/map1"
      android:layout_width="fill_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:apiKey="my map key (removed for example)"
    />
    
  • 0

    我在一台全新的机器上,没有任何东西可以测试,但这可能有效:

    <RelativeLayout 
    android:layout_width="fill_parent"          
    android:layout_height="fill_parent">
    <Button     
        android:id="@+id/btn1" 
        android:layout_width="fill_parent"          
        android:layout_height="wrap_content"
        android:text="Button1" 
        android:background="#FF0000" />
    
    <Button     
        android:id="@+id/btn2" 
        android:layout_width="fill_parent"          
        android:layout_height="wrap_content"
        android:text="Button2"
        android:background="#00FF00" />      
    
    <com.google.android.maps.MapView
        android:id="@+id/map1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:apiKey="my map key (removed for example)"
        android:layout_below="@id/btn1"
        android:layout_above="@id/btn2"
    /></RelativeLayout>
    

相关问题