MaterialSearchView +工具栏+地图

时间:2018-05-01 10:52:25

标签: android searchview

我正在尝试将搜索工具栏与Google地图集成。 这是相关部分:

<LinearLayout 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:label="MyApp"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.myapp.DrawerActivityMainActivity">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.AppBarOverlay">
    </android.support.v7.widget.Toolbar>

    <com.miguelcatalan.materialsearchview.MaterialSearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </com.miguelcatalan.materialsearchview.MaterialSearchView>

        <include layout="@layout/activity_maps"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            />
</FrameLayout>


</LinearLayout>

activity_maps.xml

<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="com.myapp.MapsActivity" />

问题是MaterialSearchView在地图上显示 bellow (即地图重叠)。如何将MaterialSearchView与工具栏和谷歌地图集成?

1 个答案:

答案 0 :(得分:0)

使用Relative Layout设置视图Below并将其与Frame Layout绑定。同时将根布局更改为Relative Layout而不是Linear Layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:label="MyApp">


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

        <FrameLayout
            android:id="@+id/frameOne"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.AppBarOverlay" />

            <com.miguelcatalan.materialsearchview.MaterialSearchView
                android:id="@+id/search_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </FrameLayout>

        <include
            layout="@layout/activity_maps"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/frameOne"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </RelativeLayout>
</RelativeLayout>

您可以查看下面的输出,似乎也可以解决此问题。

enter image description here