将MapView限制为屏幕的一半 [英] Limiting the MapView to half the screen
问题描述
我试图使地图仅填充屏幕的上半部分,而在其下半部分填充一些其他布局.现在,我知道将权重与布局一起使用应该可以实现.但是,同一段XML代码可以完美地与说按钮一起使用,而不能与地图一起使用.
此处的屏幕截图.
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.
XML代码:
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>
如果用一个按钮替换Mapview块,它将看起来像屏幕截图中的第一个图像,而现在看起来像第二个图像.
在这两种情况下,我都没有更改任何重量参数或layout_width或height,但是它以某种方式更改了大小.知道如何让MapView只能覆盖一半的屏幕吗?
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?
推荐答案
对不起,Urban,给您带来了讨厌的印象-我之前已经看过这个,而我可以通过编程方式限制地图大小的唯一方法是,但是,我此后,就使用这种类型的布局完成了此任务:
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.
这篇关于将MapView限制为屏幕的一半的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!