1

hallo the idea is to write a activity which displays a google map api v2 as a fragment and at the botton two buttons for handle a service and to generate markers on the map.

the question is now is it possible to just put the map fragment into the normal layout which defines and handles the buttons or do i have to put the buttons in another fragment?

at the moment the map covers the complete screen even if i limit the size via android:height

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/DarkGrey">


<fragment 
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="410dp"
class="com.google.android.gms.maps.SupportMapFragment" />



        <LinearLayout 
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="bottom">
            <Button 
                android:id="@+id/buttonStopTracking"
                android:text="@string/btn_stop_tracking"
                android:layout_width="160dp"
                android:layout_height="60dp"
                android:textSize="20sp" 
                android:textStyle="bold" 
                />
            <Button
                android:id="@+id/buttonCreatePoI"
                android:text="@string/btn_create_PoI"
                android:layout_width="160dp"
                android:layout_height="60dp"    
                android:textSize="20sp"
                android:textStyle="bold" 
                />
        </LinearLayout>

prototyp
  • 570
  • 6
  • 20

2 Answers2

5

I expect my layout xml will be helpful to you.

In my case, all Buttons and TextViews are located on the Google Maps. I am using the new Google Maps API v2 and my MainActivity extends "android.support.v4.app.FragmentActivity".

Here is my full xml;

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="40sp"
        android:layout_alignParentTop="true" >

    <Button
        android:id="@+id/provider_fine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_inactive"
        android:minWidth="160sp"
        android:onClick="useFineProvider"
        android:text="@string/use_fine_provider" />

    <Button
        android:id="@+id/provider_both"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_inactive"
        android:minWidth="160sp"
        android:onClick="useCoarseFineProviders"
        android:text="@string/use_both_providers" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/LinearLayout3"
        android:layout_width="match_parent"
        android:layout_height="40sp"
        android:layout_below="@+id/LinearLayout1" >

    <Button
        android:id="@+id/reset_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_inactive"
        android:minWidth="160sp"
        android:onClick="resetButton"
        android:text="@string/reset_button" />

    <Button
        android:id="@+id/calc_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_inactive"
        android:minWidth="160sp"
        android:onClick="calcButton"
        android:text="@string/calc_button" />

    </LinearLayout>




    <LinearLayout
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="95sp"
        android:orientation="vertical"
        android:layout_alignParentBottom="true" >

    <TextView
        android:id="@+id/label_latlng"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/latlng"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/latlng"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/label_address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/address"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/secondText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/distanceText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    </LinearLayout>


</RelativeLayout>

And the result screen is as follows; I removed some texts on the pic because of my privacy.

enter image description here

BBonDoo
  • 766
  • 5
  • 14
1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/DarkGrey">
        <LinearLayout 
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <fragment 
                android:id="@+id/map"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                class="com.google.android.gms.maps.SupportMapFragment" />
        </LinearLayout>


        <LinearLayout 
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="bottom">
            <Button 
                android:id="@+id/buttonStopTracking"
                android:text="@string/btn_stop_tracking"
                android:layout_width="160dp"
                android:layout_height="60dp"
                android:textSize="20sp" 
                android:textStyle="bold" 
                />
            <Button
                android:id="@+id/buttonCreatePoI"
                android:text="@string/btn_create_PoI"
                android:layout_width="160dp"
                android:layout_height="60dp"    
                android:textSize="20sp"
                android:textStyle="bold" 
                />
        </LinearLayout>
</LinearLayout>

Should do the trick I guess.

Using layout_weight is the trick.

Orientation vertical on the first layout as well.

Thibault D.
  • 10,041
  • 3
  • 25
  • 56
  • to bad doesn't work out. i played a bit with android:weight and set it at the botton LinearLayout to 6 and the android:layout_height to 0dp but still the map fragment was taking the complete screen – prototyp Feb 21 '13 at 22:02