0

I'm working with Google Maps API and I'm trying to configure the initial state of Google Maps in XML.

Whole XML code:

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

<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/test_bg"
android:scaleType="centerCrop"/>

<RelativeLayout 
   android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" >    


<RelativeLayout 
    android:id="@+id/navigation_top"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="5dp" >

    <!-- android:src="@drawable/button_back_src"    android:background="@drawable/button_background"
    android:background="@drawable/test_btn_background"-->
    <ImageButton 
        android:id="@+id/button_back"
        android:layout_width="58dp"
        android:layout_height="58dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:contentDescription="@string/desc_top_button_back"

        android:background="@drawable/btn_back"
        android:scaleType="fitXY"
        android:layout_marginRight="0dp"
        android:layout_marginLeft="@dimen/standard_margin"  
        android:layout_marginTop="@dimen/standard_margin"
        android:layout_marginBottom="0dp"
          />


    <!-- android:background="@drawable/button_background" android:background="@drawable/test_btn_background" android:src="@drawable/button_options_src"-->
    <ImageButton 
        android:id="@+id/button_options"
        android:layout_width="58dp"
        android:layout_height="58dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"

        android:contentDescription="@string/desc_top_button_options"
        android:background="@drawable/btn_options"
        android:scaleType="fitXY"
        android:layout_marginRight="@dimen/standard_margin"
        android:layout_marginLeft="0dp"  
        android:layout_marginTop="@dimen/standard_margin"
        android:layout_marginBottom="0dp" />


    <!-- background, android:dropDownSelector="@drawable/spinner_selector_small"  -->
    <Spinner 
        android:id="@+id/spinner"
        android:layout_height="58dp"
        android:layout_width="wrap_content"
        android:layout_toLeftOf="@+id/button_options"
        android:layout_toRightOf="@+id/button_back"
        android:spinnerStyle="@android:style/Widget.Spinner.DropDown"
        android:background="@drawable/test_spinner_style"   
        android:padding="5dp"
        android:layout_marginRight="0dp"
        android:layout_marginLeft="0dp"  
        android:layout_marginTop="5dp"
        android:layout_marginBottom="0dp" />

</RelativeLayout>

    <LinearLayout 
        android:id="@+id/layout_checkpoints"

        android:minHeight="24dp"
        android:layout_below="@+id/navigation_top"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:background="@android:color/transparent">

    </LinearLayout>

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignTop="@+id/layout_checkpoints"
    android:layout_centerHorizontal="true"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_marginLeft="@dimen/double_margin"
    android:layout_marginRight="@dimen/double_margin"
    android:layout_marginBottom="68dp" />

<LinearLayout
    android:id="@+id/rounded_corners_for_map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignBottom="@+id/map"
    android:layout_alignLeft="@+id/map"
    android:layout_alignRight="@+id/map"
    android:layout_below="@+id/navigation_top"
    android:background="@drawable/round_corners"
    android:orientation="horizontal" >

</LinearLayout>

<ImageView 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:scaleType="fitXY" 
    android:src="@drawable/splash" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:id="@+id/splash_screen" 
    android:layout_alignParentBottom="true"/>

As you can see, I added

xmlns:map="http://schemas.android.com/apk/res-auto"

to FramLayout at the beginning. However, when I try to use the map prefix it won't let me.

I'm trying to do it like this:

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignTop="@+id/layout_checkpoints"
    android:layout_centerHorizontal="true"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_marginLeft="@dimen/double_margin"
    android:layout_marginRight="@dimen/double_margin"
    android:layout_marginBottom="68dp"
    map:uiZoomControls="false" />

But it underlines the map:uiZoomControls="false" and says Unexpected namespace prefix "map" etc.

Any idea what am I doing wrong?

Guy
  • 6,414
  • 19
  • 66
  • 136

1 Answers1

3

I think you just have to try this :

<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
map:uiZoomControls="false"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@+id/layout_checkpoints"
android:layout_centerHorizontal="true"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginLeft="@dimen/double_margin"
android:layout_marginRight="@dimen/double_margin"
android:layout_marginBottom="68dp"
 />

Other ideas :

  • add tools:ignore="MissingPrefix" in your fragment
  • Be sur that you have add the dependency to Google Play Services in your project (Project -> Properties -> Android -> Library, Add -> google-play-services_lib)
Adrien Cerdan
  • 1,005
  • 1
  • 11
  • 21
  • Already tried that, it underlines the whole xmlns:map... and says unexpected name prefix again (same error), it only works if I add it to FrameLayout. – Guy Nov 10 '13 at 22:42
  • Yes! Thank you very much! tools:ignore="MissingPrefix" did the job :) – Guy Nov 10 '13 at 22:54
  • Well, it sure did remove the error to the eye, but the error is still in the code. Just not highlighted. – 7heViking May 07 '16 at 07:01