【问题标题】:Limiting the MapView to half the screen将 MapView 限制为屏幕的一半
【发布时间】:2017-03-28 11:37:03
【问题描述】:

我正在尝试让地图仅填充屏幕的上半部分,并在下半部分填充其他一些布局。现在我知道这应该可以结合使用权重和表格布局来实现。但是同一段 XML 代码完美地适用于说按钮,但不适用于地图。
Screenshots here

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 块,它将看起来像屏幕截图中的第一张图片,而现在它看起来像第二张。
在这两种情况下,我都没有更改任何重量参数或 layout_width 或 height,但它以某种方式改变了大小。知道如何让 MapView 只覆盖一半屏幕吗?

【问题讨论】:

  • 我认为唯一的方法就是以编程方式进行。
  • 您不要将layout_widthlayout_heightTableLayoutTableRow 一起使用。切换到嵌套的LinearLayouts,或者使用RelativeLayout,什么的。
  • @CommonsWare thx 帮助...我需要停止使用 tablelayout 这么多..

标签: android android-mapview google-maps-mobile


【解决方案1】:

抱歉,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" /> 

显示的最后一项是自定义小部件,但布局应显示所涉及的原则。这限制了地图的高度,但允许它全宽。

【讨论】:

  • 谢谢@John。我改用了Linearlayout,但它基本上是一样的......不知道是什么让我首先使用表格>。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多