在TabLayout内滚动recyclerView时隐藏Fragment中的工具栏

时间:2018-10-23 05:35:23

标签: android android-fragments android-tablayout android-coordinatorlayout

我的应用程序包含一个BottomNavigation视图,其中包含4个片段。在fragment之一中,包含一个ToolbarSearchview和标签页布局。在带有2个标签的标签布局内部,每个标签都包含一个片段,其中包含recyclerview。现在,我想在标签布局toolbar内的recyclerview中滚动时隐藏fragment

enter image description here

搜索片段的布局:

  <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/textcolor">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/app"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

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

    <Button
        android:id="@+id/back"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_gravity="start"
        android:layout_marginRight="5dp"
        android:layout_marginEnd="5dp"
        android:background="@drawable/backblack" />


</android.support.v7.widget.Toolbar>

    <LinearLayout
        android:id="@+id/layloc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:orientation="horizontal"
        android:weightSum="1"
        android:padding="5dp"
        android:background="@drawable/border">


        <TextView
            android:id="@+id/locationname"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/location"
            android:drawableLeft="@drawable/location"
            android:drawablePadding="3dp"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal"
            android:textColor="@color/cblack"
            android:text="fetching current location"/>          

        <TextView
            android:id="@+id/change"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Change"
            android:drawablePadding="3dp"
            android:textColor="@color/cblack"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>

    </LinearLayout>



<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/layloc"
    android:background="@color/textcolor"
    app:tabTextColor="@color/black"
    app:tabPaddingStart="0dp"
    app:tabPaddingEnd="0dp" />

</android.support.design.widget.AppBarLayout>




<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/app"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


 </RelativeLayout>

Tablayout内部的布局:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/textcolor"
android:id="@+id/mainexplore">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:visibility="gone"
    android:id="@+id/lin">

    <com.github.chrisbanes.photoview.PhotoView
        android:id="@+id/expanded_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:background="@color/cblack"
        android:src="@drawable/place"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"/>

    <ImageButton
        android:id="@+id/clear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="mmm"
        android:layout_margin="15dp"
        android:background="@null"
        android:padding="3dp"
        android:src="@android:drawable/ic_menu_close_clear_cancel"
        app:srcCompat="@android:drawable/ic_menu_close_clear_cancel"/>

</RelativeLayout>

<ListView
    android:id="@+id/lists"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@drawable/list_divider"
    android:dividerHeight="1px"
    android:scrollbars="none"
    android:visibility="gone" />

<TextView
    android:id="@+id/emptyElement"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="@string/nofound"
    android:textColor="@color/button"
    android:visibility="gone"/>

 </RelativeLayout>

我已经搜索过SO,但大多数答案是与Activity中的Fragment交易。因此,如何在Fragment的Tablayout中的RecyclerView中滚动时隐藏工具栏。

0 个答案:

没有答案