【发布时间】:2016-02-10 21:07:54
【问题描述】:
我有一个带有 3 个片段的 viewpager,它们正在使用 recyclerviews。当用户滚动回收视图时,我试图隐藏工具栏。我的问题是工具栏在用户滚动时隐藏/显示,但没有完全隐藏。我不明白我做错了什么。为了说明究竟发生了什么,我将两张图片与工具栏的两种状态(隐藏和显示)一起添加。
注意:工具栏隐藏时我注意到的一件事。它不会像应有的那样位于系统状态栏“下方”,而是位于其上方。
可以看出,工具栏没有完全隐藏。我可以在右侧看到部分工具栏标题和溢出图标。
这是我的 main_layout xml:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.studentsins.lust.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/NavigationTab"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<include layout="@layout/content_main"/>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/floatingActionMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="@color/blood_orange"
fab:fab_addButtonColorPressed="@color/dirtyWhite"
fab:fab_addButtonPlusIconColor="@color/dirtyWhite"
fab:fab_addButtonSize = "normal"
fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_labelsPosition="left"
app:layout_anchor="@id/viewpager"
app:layout_anchorGravity="bottom|end">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/createPlanBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/blood_orange"
fab:fab_title="Create a plan"
fab:fab_size="normal"
app:fab_icon="@drawable/ic_event_white_48dp"
fab:fab_colorPressed="@color/dirtyWhite"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/changeStatusBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/blood_orange"
fab:fab_size="normal"
app:fab_icon="@drawable/ic_textsms_white_48dp"
fab:fab_title="Change status"
fab:fab_colorPressed="@color/dirtyWhite"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
重叠可能是因为标签布局的高度大于工具栏的高度。
-
嗯,怎么改?
-
尝试将tabLayout高度设置为android:layout_height="?attr/actionBarSize"
-
@davehenry 我恢复了波纹管应用的更改并尝试了您的建议,它奏效了!非常感谢!请您添加您的评论作为答案,以便我接受它,因为您的建议实际上解决了原始问题。我只找到了一个工作区。
-
谢谢!很高兴它有帮助!
标签: android toolbar android-coordinatorlayout