Android - MapFragment,TextView和Button在上面

时间:2014-10-02 07:28:07

标签: android relativelayout mapfragment

我正在尝试使mapfragment工作,以便地图显示在按钮和文本视图下方。

使用下面的布局,地图可以正常工作,但按钮和文本视图会占用屏幕底部的空间。

我尝试了各种选项,例如将布局更改为相对布局等,但是当我使用相对布局时,地图根本不会显示。

有没有办法达到我想要的目的?

<?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" >

    <fragment
        android:id="@+id/map"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        class="com.google.android.gms.maps.MapFragment" />

    <AutoCompleteTextView
        android:id="@+id/stationName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="24dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginTop="16dp"
        android:fontFamily="sans-serif-condensed"
        android:hint="Select/Type station name to track"
        android:text="" />

    <Button
        android:id="@+id/but1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/stationName"
        android:background="@drawable/black_button"
        android:fontFamily="sans-serif-condensed"
        android:text="Start Tracking"
        android:textColor="@color/white"
        android:textSize="20dp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="15dp"
        android:textAlignment="center"
        android:textSize="14dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingTop="15dp"
        android:textAlignment="center"
        android:textSize="14dp" />

</LinearLayout>

1 个答案:

答案 0 :(得分:1)

  

我正在尝试使mapfragment工作,以便地图显示   在按钮和文本视图下方。

您需要FrameLayout。子视图以堆栈形式绘制,最近添加的子项位于顶部。这足以满足您的需求。