Limiting the MapView to half the screen

老子叫甜甜 提交于 2019-12-23 16:41:59

问题


I am trying to get the map to fill in only the upper half of the screen and some other layout in the bottom half. Now I know that this should be possible using weights in combination with a tablelayout. But the same piece of XML code works perfectly with say buttons but not with map.
Screenshots here.

The XML code:

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" 
        >
            <com.google.android.maps.MapView
            android:id="@+id/map2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:apiKey="0_z4IHjB6EnXohnoyoudontgoVmhg"
            android:clickable="true" >
        </com.google.android.maps.MapView>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >
        <Button android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="SECOND"></Button>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >
        <Button android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="SECOND"></Button>
    </TableRow>
</TableLayout>

If you replace the Mapview block by say a button, it will look like the first image in the screenshot, whereas right now it looks like the second one.
In both cases I did not change any weight parameters or layout_width or height, but it somehow changes the size. Any idea how can I have the MapView to cover only half the screen?


回答1:


Sorry Urban, gave you a bum steer on it - I had looked at this before and the only way I could limit the map size was programmatically, however, I have since done it with this type of layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"     
 android:orientation="vertical" >          

 <FrameLayout android:id="@+id/map_frame"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="0.7" >     

    <com.google.android.maps.MapView
        android:id="@+id/map_view" 
        android:layout_width="fill_parent"
        android:layout_height="match_parent" 
        android:enabled="true" 
        android:clickable="true"             
        android:apiKey="dgvbdj_my_secret_key_nvc8mxcksos"/>

 </FrameLayout>

 <co.uk.mycompany.ui.MapNavBar
    android:id="@+id/map_nav"
    android:layout_width="fill_parent"
    android:layout_height="70dip"
    android:layout_gravity="bottom"
    android:layout_weight="0.3" /> 

The last item shown is a custom widget but the layout should show the principles involved. This limited the map height but allowed it to go full width.



来源:https://stackoverflow.com/questions/8107008/limiting-the-mapview-to-half-the-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!