将 MapView 限制为屏幕的一半
我试图让地图仅填充屏幕的上半部分,并在下半部分填充一些其他布局。现在我知道使用权重与表格布局相结合应该可以实现这一点。但是同一段 XML 代码可以完美地与 say 按钮配合使用,但不能与地图配合使用。
此处的屏幕截图。
XML 代码:
<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 块,它将看起来像屏幕截图中的第一个图像,而现在它看起来像第二个图像。
在这两种情况下,我都没有更改任何权重参数或布局宽度或高度,但它以某种方式改变了大小。知道如何让 MapView 只覆盖一半屏幕吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,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:
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.