我试图让地图仅填充屏幕的上半部分,并在下半部分填充一些其他布局。现在我知道使用权重与表格布局相结合应该可以实现这一点。但是同一段 XML 代码可以完美地与 say 按钮配合使用,但不能与地图配合使用。
截图在这里 https://i.stack.imgur.com/oBoJB.jpg.
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 只覆盖一半屏幕吗?
抱歉,Urban,给了你一个错误的指导 - 我之前已经看过这个,我可以限制地图大小的唯一方法是以编程方式,但是,我已经用这种类型的布局完成了它:
<?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" />
显示的最后一项是自定义小部件,但布局应显示所涉及的原理。这限制了地图高度,但允许其全宽。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)