在TabLayout中,我有两个选项卡,其中在第一个选项卡中将FrameLayout与recyclerView放在一起,在第二个选项卡中放置带有LinerLayout的ScrollView。在任何选项卡中滚动时,我都需要隐藏ToolBar。当我在第一个选项卡工具栏中滚动RecyclerView时,当我在第二个选项卡中滚动时,它不是。不能忍受为什么。
我有这个main_acrivity.xml
<FrameLayout 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:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
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="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabIndicatorColor="@android:color/background_light"
app:tabSelectedTextColor="@android:color/background_light"
app:tabTextColor="@android:color/background_light"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
发布于 2016-04-08 11:37:38
新的滚动行为将不适用于常规的android.widget.ScrollView
,因为它不支持嵌套滚动。
滚动行为依赖于支持嵌套滚动的视图,在视图树上传播滚动事件,以便工具栏知道何时滑动和隐藏。
它与RecyclerView一起工作的原因是它默认支持嵌套滚动。
你需要的是一个NestedScrollView
NestedScrollView就像ScrollView一样,但它支持在新版本和旧版本的Android上同时充当嵌套滚动父级和子级。默认情况下,启用嵌套滚动。
因此,在具有ScrollView的布局中,将其替换为android.support.v4.widget.NestedScrollView
,滚动视图行为将如预期的那样工作:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- your content here...... -->
</android.support.v4.widget.NestedScrollView>
https://stackoverflow.com/questions/36506969
复制相似问题