android - 将 float 操作按钮与滑动的选项卡一起移动

标签 android material-design floating-action-button

让我简要介绍一下我的想法和我想要实现的目标,

想法是有一个包含三个选项卡的滑动选项卡,每个选项卡屏幕由一个单独的 Fragment 类表示。我使用“it.neokree:MaterialTabs:0.11”库完成了这项工作,一切正常。 然后,我使用“com.oguzdev:CircularFloatingActionMenu:1.0.2”库创建了一个 float 操作按钮 (FAB)。

现在 我想要实现的是将此 FAB 固定到中心选项卡中的 fragment ,当我滑动屏幕以转到上一个或下一个选项卡时,FAB 应该与选项卡 fragment 一起滑出它在里面,当我滑回它时,它应该会与中心标签屏幕一起滑回

我一直在研究它,现在我可以隐藏其他 fragment 中的 View ,并通过覆盖每个 fragment 类中的 setUserVisibleHint() 方法再次在中心 fragment 中显示它,就像这样.

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
   if (isVisibleToUser) {
       View tempView = getActivity().findViewById(R.id.myFAB);
       tempView.setVisibility(View.INVISIBLE);
      }
}

但问题是我希望 FAB 像选项卡 fragment 类中的其他 View 一样与中心选项卡一起滑出和滑入,但我的 FAB 只是消失并重新出现。

在某种程度上,我希望 FAB 专用于中心选项卡,并且应该固定到它。

我还尝试在中心 Fragment 类中定义 FAB,但它似乎没有任何区别。任何意见和建议都会非常有帮助。提前致谢

最佳答案

此库将其 View 添加到“android.R.id.content”ViewGroup。这就是为什么在何处定义它并不重要。

动画这样的 View 可能很困难,但应该是可能的。您在手动滑动寻呼机时翻译了 FAB。

顺便说一下,Google 建议隐藏 FAB,而不是滑动:

For tabbed screens, the floating action button should not exit the screen in the same direction as the screen exits. Doing so creates visual noise. It would also cause a nonfunctional floating action button to appear on screen. Furthermore, it incorrectly implies that the floating action button is at the same the z-level as the content, rather than at the level of the primary UI elements at the root level.

参见:http://www.google.com/design/spec/components/buttons-floating-action-button.html#buttons-floating-action-button-behavior

关于android - 将 float 操作按钮与滑动的选项卡一起移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30817444/

相关文章:

android - 在 Android 中的 Activity 之间共享复杂的对象树的好选择?

html - 尝试错开 Material Design 卡片并使其均匀分布在行中

android - 使用 MaterialToolbar 在 AppBarLayout 中居中标题

android - 在键盘上方设置 FAB( float 操作按钮)

java - onClickListener() 不适用于 FloatingActionButton 和工具栏图标

java - 尝试在 Android Studio 2.2.1 中运行新项目时出错

android - 从蓝牙连接的 Android 应用程序控制 Arduino 上的 LED 的问题

java - Android:如何检索解析的值

android - SlidingTabLayout 选项卡之间的通信

android - 如何在 FloatingActionButton 上显示图标?