如何在 Android 中的 google 地图下方放置两个对齐的按钮

How to place two aligned buttons below google map in Android

如何在 Android 中的 google 地图下方放置两个按钮?

我在下面使用这段代码,它工作正常,但问题是
地图也在按钮后面。我想在按钮上方设置地图的高度。我如何
调整地图的大小并将地图底部均匀地
放置在从中心分布的两个按钮上方?

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >

<fragment
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_alignParentRight="true"
  android:layout_below="@+id/editText1"
  class="com.google.android.gms.maps.SupportMapFragment" />

<Button
  android:id="@+id/button1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignBottom="@+id/editText1"
  android:layout_alignParentRight="true"
  android:layout_alignParentTop="true"
  android:text="Button" />

<EditText
  android:id="@+id/editText1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentLeft="true"
  android:layout_alignParentTop="true"
  android:layout_toLeftOf="@+id/button1"
  android:ems="10" >
  <requestFocus />
  </EditText>

<Button
 android:id="@+id/maptype"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true"
 android:layout_alignParentRight="true"
 android:layout_alignTop="@+id/hello"
 android:layout_toRightOf="@+id/view"
 android:text="First" />
<View
    android:id="@+id/view"
    android:layout_width="0dp"
    android:layout_height="1dp"
    android:layout_centerHorizontal="true" />
<Button
    android:id="@+id/hello"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignRight="@+id/view"
    android:layout_alignTop="@+id/map"
    android:layout_marginTop="346dp"
    android:text="Second" />
</RelativeLayout>

而不是 @+id/hello button 中的 android:layout_alignTop="@+id/map" 尝试片段中的 android:layout_above="@+id/maptype"。 请注意,我必须删除片段中的 class 并为其添加 android:name

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >

<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="com.google.android.gms.maps.MapFragment"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_above="@+id/maptype"
    android:layout_below="@+id/editText1"
    />
    <!--class="com.google.android.gms.maps.SupportMapFragment" />-->

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Button" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/button1"
    android:ems="10" >
    <requestFocus />
</EditText>

<Button
    android:id="@+id/maptype"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/hello"
    android:layout_toRightOf="@+id/view"
    android:text="First" />
<View
    android:id="@+id/view"
    android:layout_width="0dp"
    android:layout_height="1dp"
    android:layout_centerHorizontal="true" />
<Button
    android:id="@+id/hello"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignRight="@+id/view"
    android:layout_marginTop="346dp"
    android:text="Second"
    />
    <!--android:layout_alignTop="@+id/map"-->

</RelativeLayout>

编辑:Link 完整 XML: https://gist.github.com/anonymous/75c66e9b4266d45d6b62#file-gistfile1-txt

尝试将地图片段的 layout_height 设置为 0dp,将 layout_weight 设置为 1。 这对我来说很好!以前,地图下方的一切都是看不见的。 这个 link 可能有用: Create buttons below google map