Android:CollapsingToolbar在向下滚动后隐藏

问题描述:

我的布局包含折叠工具栏和带有ViewPager的Tablayout如果向下滚动并向上滚动,CollapsingToolbar会隐藏。我必须拖动tablayout或swiperefresh以使CollapsingToolbar可见。我向上滚动后应该可见工具栏。请帮忙。 这里是我的布局:Android:CollapsingToolbar在向下滚动后隐藏

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 


    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff"> 

    <RelativeLayout 
     android:id="@+id/main_frame_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.design.widget.CoordinatorLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true"> 

      <android.support.design.widget.AppBarLayout 
       android:id="@+id/dashboard_app_bar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ffffff" 
       android:stateListAnimator="@null" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

       <android.support.design.widget.CollapsingToolbarLayout 
        android:id="@+id/collapsing_toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        app:contentScrim="@color/light_red" 
        app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

        <RelativeLayout 
         android:id="@+id/relative_banner" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         app:layout_collapseMode="parallax"> 

         <android.support.v4.view.ViewPager 
          android:id="@+id/dashboard_img_banner_view_pager" 
          android:layout_width="match_parent" 
          android:layout_height="180dp" 
          android:layout_marginTop="60dp" 
          app:layout_collapseMode="parallax" /> 

         <me.relex.circleindicator.CircleIndicator 
          android:id="@+id/dashboard_circular_indicator_one" 
          android:layout_width="match_parent" 
          android:layout_height="20dp" 
          android:layout_alignBottom="@+id/dashboard_img_banner_view_pager" 
          android:layout_marginBottom="10dp" 
          android:background="@android:color/transparent" /> 
        </RelativeLayout> 

        <android.support.v7.widget.Toolbar 
         android:id="@+id/toolbar" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_alignParentTop="true" 
         android:background="@color/red_color" 
         app:contentInsetLeft="0dp" 
         app:contentInsetStart="0dp" 
         app:contentInsetStartWithNavigation="0dp" 
         app:layout_collapseMode="pin"> 

         <RelativeLayout 
          android:id="@+id/rl_city_choice" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:clickable="true"> 

          <ImageView 
           android:id="@+id/toolbar_img" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_alignParentLeft="true" 
           android:layout_alignParentStart="true" 
           android:src="@drawable/location" /> 

          <org.offer_katta_ok.utils.CustomView.CustomRegularTextView 
           android:id="@+id/txt_city_name" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_centerVertical="true" 
           android:layout_marginLeft="2dp" 
           android:layout_marginStart="2dp" 
           android:layout_toEndOf="@+id/toolbar_img" 
           android:layout_toRightOf="@+id/toolbar_img" 
           android:text="@string/city" 
           android:textColor="#ffffff" /> 
         </RelativeLayout> 
        </android.support.v7.widget.Toolbar> 

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

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:behavior_overlapTop="0dp" 
       app:layout_anchor="@+id/dashboard_app_bar" 
       app:layout_anchorGravity="bottom" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="1dp" 
        android:background="@color/uncheck_radio_grey" /> 

       <android.support.design.widget.TabLayout 
        android:id="@+id/tab_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="bottom" 
        app:behavior_overlapTop="0dp" 
        app:layout_collapseMode="none" 
        app:tabGravity="fill" 
        app:tabMode="fixed" 
        app:tabSelectedTextColor="@color/tab_text_color" 
        app:tabTextAppearance="@style/MyTabLayoutTextAppearance" 
        app:tabTextColor="@color/text_sub_content_color" /> 

       <android.support.v4.widget.SwipeRefreshLayout 
        android:id="@+id/refresh" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/tab_layout"> 

        <org.offer_katta_ok.home.pagerAdapter.CustomViewPager 
         android:id="@+id/pager" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/tab_layout" /> 

       </android.support.v4.widget.SwipeRefreshLayout> 

       <GridView 
        android:id="@+id/grid_category" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_below="@+id/tab_layout" 
        android:background="@color/white" 
        android:horizontalSpacing="2dp" 
        android:numColumns="2" 
        android:padding="10dp" 
        android:scrollbars="none" 
        android:verticalSpacing="2dp" 
        android:visibility="gone" /> 
      </RelativeLayout> 

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

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/float_category" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_marginBottom="50dp" 
      android:layout_marginEnd="5dp" 
      android:layout_marginRight="5dp" 
      android:scaleType="fitXY" 
      android:src="@drawable/categories1" 
      app:fabSize="mini" 
      app:rippleColor="@android:color/transparent" /> 

    </RelativeLayout> 
    <!-- The navigation drawer --> 
    <ExpandableListView 
     android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="#77000000" 
     android:cacheColorHint="@android:color/transparent" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="2dp" 
     android:groupIndicator="@null" 
     android:listSelector="@color/red_color" /> 


</android.support.v4.widget.DrawerLayout> 

我面临着类似的照片与图像张贴在这个问题上的问题:

Android: CollapsingToolbarLayout and SwipeRefreshLayout get stuck

+0

请张贴截图 –

没有截图/ GIF很难理解,但我会尽力。 您需要滚动标记enterAlways,以便在您开始向上滚动时即可看到该视图。

CollapsingToolbarLayout

app:layout_scrollFlags="scroll|enterAwalys" 

另见文档:https://developer.android.com/reference/android/support/design/widget/AppBarLayout.LayoutParams.html

+1

由于它的工作... @fillobotto – madhura21