마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

Google map acitivity에 검색바 넣기

0 추천
구글맵api를 이용해 플젝하는데,

구글맵 액티비티 상단에 검색바를 만들려고 하는데 xml에 아무것도 추가가 되지 않더라고요.

fragment로 되어있는데

 

검색바를 넣고 거기다가 입력하면 디비에서 정보를 띄워야하는데 초보는 웁니다 ㅜㅜㅜ
익명사용자 님이 2016년 5월 27일 질문

1개의 답변

0 추천

google map v2 api를 사용하고 계시다면 아래와 같은 fragment로 map을 추가하실 겁니다

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

 

이것을 framelayout으로 감싸주셔서 map위에 검색창을 올리시면 되겠습니다.

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/layout_mapscreen"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

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

        <LinearLayout
            android:id="@+id/layout_mapscreen_search"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <!-- search bar -->
       </LinearLayout>
</FrameLayout>

     

혹은 RelativeLayout으로 감싸서 하셔도 되겠습니다.

주의할 사항은 map을 먼저 그려놓고 다른걸 올리셔야 map위에 원하는 ui가 올라가게 됩니다

prague (26,200 포인트) 님이 2016년 5월 27일 답변
저렇게 감싸도 에러가 뜨네요. FrameLayout, LinearLayout에 빨강 및줄, android가 빨갛게 변해버리네요.. ㅠㅠㅠㅠ
<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="kr.co.company.mainactivity_map.myact"
    map:cameraZoom="16"
    map:mapType="normal"
    />
    <!--최초 줌사이즈 15, 지도타입 노말-->
최초 이렇게 되어있고 주석부분만 제가 넣은겁니다.
FrameLayout에 namespace가 없네요. Layout파일은 XML 문서이기 때문에 property를 사용하시려면 해당 namespace를 등록해주셔야 합니다. framgment tag에 있는 namespace들을 FragmentLayout 쪽으로 옮겨주세요.

Layout은 XML 문서이므로 해당 속성을 사용하려면 최상위 tag에 namespace를 넣어주셔야 합니다.

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

</FrameLayout>
...