Ivan Fuertes Ivan Fuertes - 1 month ago 5
Android Question

How to place two aligned buttons below google map in Android

How do I place two buttons below google map in Android?

I use this code below it works fine but the problem
is the map are also behind the buttons. I want to set the height of the map above the buttons. How
will I be able to resize the map and place the bottom of the map above the two buttons equally
distributed from the center?




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

Answer

Instead of android:layout_alignTop="@+id/map" in @+id/hello button try android:layout_above="@+id/maptype" in fragment. Note that I have to remove the class in fragment and add the android:name for it

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

EDIT: Link for full XML: https://gist.github.com/anonymous/75c66e9b4266d45d6b62#file-gistfile1-txt