Maverick
Maverick

Reputation: 105

Overlay autocomplete fragment on map fragment

I'm trying to overlay a autocomplete fragment over a mapfragment. Problem is my autocomplete is transparent, it does not get the white background i set. Any tips on this?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity"
    android:layout_gravity="center_horizontal|bottom" />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/place_autocomplete_fragment"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:background="#FFFFFF"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
</FrameLayout>
</FrameLayout>

Upvotes: 5

Views: 4662

Answers (1)

Tom
Tom

Reputation: 58

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    map:uiZoomControls="true"
    map:uiZoomGestures="true"
    map:mapType="normal"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MapsActivity">
    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.greenfeetsurvival.greenfeetaviator.MapsActivity">
        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view"
            android:layout_gravity="top"
            android:layout_margin="5dp"
            android:layout_width="200dp"
            android:layout_height="40dp"
            card_view:cardCornerRadius="4dp">
            <fragment
                android:id="@+id/place_autocomplete_fragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"    
                android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
        </android.support.v7.widget.CardView>
    </fragment>
</LinearLayout>

This is the layout I used in my app. The PlaceAutocompleteFragment looks exactly like the Google tool. It sits at the top left corner on top of the map with a 5dp margin.

Upvotes: 4

Related Questions