自定义MaterialSearchView显示在片段中的工具栏下

时间:2016-07-15 17:50:45

标签: android android-layout android-fragments

我正在使用自定义MaterialSearchview,我的项目如下:

布局:

MainLayout
FragmentSection Layout

代码:

MainActivity 
SectionFragment

在MainActivity中有一个Drawer库,我有6个部分,其中只有一个片段有一个Search图标,所以这就是我的问题。

在主布局中,我有一个工具栏和一个片段:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.abohani.ramadantime.MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways|snap"
    android:minHeight="@dimen/abc_action_bar_default_height_material"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />




<FrameLayout
    android:id="@+id/fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/toolbar" />

</RelativeLayout>

正如您所看到的,片段位于工具栏下,因此在进行事务处理时,搜索显示在工具栏下,为什么?

因为我在我的片段布局中添加了searchview,并且我正在使用片段布局重新生成MainLayout @id / fragment,并且该片段视图位于toolbar =&gt;下Searchview显示在。

之下

我需要什么?我想帮助解决这个问题,它有不同的逻辑吗?

这是我的片段布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rel"
android:orientation="vertical">

<com.lapism.searchview.SearchView
    android:id="@+id/searchView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

<android.support.v7.widget.RecyclerView
    android:id="@+id/fav_rv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/no_match"
    android:visibility="invisible"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

<include
    android:id="@+id/loading_layout"
    layout="@layout/loading_progress"/>



</RelativeLayout>

0 个答案:

没有答案