MapView not supporting layout_height=wrap_content
I'm building a layout that contains two buttons and a MapView. The buttons should be placed above and below the MapView. I've tried several combinations of layouts (Relative, Linear, Frame...), but the MapView does not support the layout_height=wrap_content unless I use a specific height like layout_height="200dp".
The tope button is displayed, but the bottom button is not. Below is my test XML file.
Any suggestions?
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" />
I had the same issue (my mapview was between two layouts instead of buttons), and solved it with "height=0dp" and "weight=1" so the mapview adjusts to the above and below layouts.
<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)"
/>
I'm on a brand new machine and don't have anything to test this with, but this might work:
<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>
精彩评论