我正在尝试从Android设计支持库中获取一个浮动操作按钮,该按钮位于ViewPager内部的Fragment中。我有4个选项卡,并且只想在其中一个选项卡中使用FAB。我的布局如下所示:
现在的问题是,FAB不能按照设计规范工作,即隐藏和显示FAB不起作用。而且,在激活片段时,FAB不在其初始位置。我已经附上截图以使内容更加清晰。
左侧图片中,您可以看到FAB离开了屏幕。当我滚动时,工具栏会隐藏(类似于Play Store应用程序),而选项卡保留,这时FAB将向上滚动。
这是Design Support库中的错误吗?还是我的布局不正确?此外,我只想在一个片段中使用FAB,因此在main_layout.xml中添加FAB有点违背初衷。
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"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<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/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabIndicatorHeight="3dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</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" />
list_fragment_with_fab.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="5dip"
android:background="@color/Transparent_White"
android:fitsSystemWindows="false"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.lucasr.twowayview.widget.TwoWayView
android:id="@+id/clip_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:twowayview_layoutManager="ListLayoutManager" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_list_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/ic_list_add"
app:layout_anchor="@+id/clip_recycler_view"
app:layout_anchorGravity="bottom|right|end" />
现在的问题是,FAB不能按照设计规范工作,即隐藏和显示FAB不起作用。而且,在激活片段时,FAB不在其初始位置。我已经附上截图以使内容更加清晰。
左侧图片中,您可以看到FAB离开了屏幕。当我滚动时,工具栏会隐藏(类似于Play Store应用程序),而选项卡保留,这时FAB将向上滚动。
这是Design Support库中的错误吗?还是我的布局不正确?此外,我只想在一个片段中使用FAB,因此在main_layout.xml中添加FAB有点违背初衷。