我的布局包括使用ViewPager折叠工具栏和Tablayout如果我向下滚动并向上滚动,CollapsingToolbar会被隐藏。我必须向下拖动tablayout或swiperefresh以使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>
我面临的问题类似于此问题中发布的Gifs:
Android: CollapsingToolbarLayout and SwipeRefreshLayout get stuck
答案 0 :(得分:1)
没有截图/ gif很难理解,但我会尝试。
您需要滚动标记enterAlways
,以便在您开始向上滚动时可以看到该视图。
在CollapsingToolbarLayout
:
app:layout_scrollFlags="scroll|enterAwalys"
另见文档:https://developer.android.com/reference/android/support/design/widget/AppBarLayout.LayoutParams.html