让我简要介绍一下我的想法和我想要实现的目标,
想法是有一个包含三个选项卡的滑动选项卡,每个选项卡屏幕由一个单独的 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.
关于android - 将 float 操作按钮与滑动的选项卡一起移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30817444/