【发布时间】:2016-06-14 10:32:06
【问题描述】:
我有一个选项卡式活动。有两个选项卡。选项卡 1 和选项卡 2 的唯一区别是,选项卡 1 有浮动操作按钮,选项卡 2 没有。
在标签 1 中:
- 当用户向下滚动回收站视图时,工具栏和浮动操作按钮应该会消失。
- 当用户向上滚动回收站视图时,应该会出现工具栏和浮动操作按钮。
在标签 2 中:
- 当用户向下滚动回收站视图时,工具栏应该会消失。
- 当用户向上滚动回收站视图时,工具栏应该会出现。
标签 2 效果很好,标签 2 没有问题。但是标签 1 不能正常工作。向下滚动回收站视图时,工具栏不会消失。向上滚动回收站视图时,工具栏不会出现。此外,选项卡 1 并未显示所有页面。回收站视图中有 40 个项目,但选项卡 1 显示 39 个项目。而且它没有显示所有浮动操作按钮。
我认为问题的原因是fragment_tab1.xml 中的协调器布局。因为当我删除它时,工具栏会消失并在滚动时出现。但是浮动操作按钮在滚动时不会消失并出现。
这是视频:http://sendvid.com/hyaorcss
activity_main.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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.fab.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"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabGravity="fill"
app:layout_collapseMode="pin" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml:
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="6dp"
android:paddingRight="6dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.fab.MainActivity"
tools:showIn="@layout/activity_main">
<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"/>
</RelativeLayout>
fragment_tab1.xml:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/tab1SwipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/tab1RecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:clickable="true" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="@android:drawable/ic_dialog_email"
app:layout_anchor="@id/tab1RecyclerView"
app:layout_behavior="com.example.fab.ScrollAwareFABBehavior"
app:layout_anchorGravity="bottom|right|end"
android:id="@+id/emailFab"/>
</android.support.design.widget.CoordinatorLayout>
fragment_tab2.xml:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tab2SwipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab2RecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:clickable="true" />
</android.support.v4.widget.SwipeRefreshLayout>
【问题讨论】:
标签: android android-toolbar android-coordinatorlayout floating-action-button swiperefreshlayout