将浮动操作按钮与滑动的选项卡一起移动
Move the Floating Action Button along with the swiped tab
让我简要介绍一下我的想法和我想要实现的目标,
想法是有一个包含三个选项卡的滑动选项卡,每个选项卡屏幕由一个单独的片段表示 class。我使用 "it.neokree:MaterialTabs:0.11" 库完成了此操作,并且一切正常。
然后我使用 "com.oguzdev:CircularFloatingActionMenu:1.0.2" 库创建了一个浮动操作按钮 (FAB)。
现在 我想要实现的是将此 FAB 固定到中心选项卡中的片段,当我滑动屏幕以转到上一个或下一个选项卡时,FAB 应该一起滑出标签片段在其中,当我滑回它时,应该会与中心标签屏幕一起滑回。
到目前为止我一直在研究它,现在我可以在其他片段中隐藏视图并通过重写每个片段中的 setUserVisibleHint()
方法在中心片段中再次显示它 class 就像这个。
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
View tempView = getActivity().findViewById(R.id.myFAB);
tempView.setVisibility(View.INVISIBLE);
}
}
但问题是我希望 FAB 与中心选项卡一起滑出和滑入,就像选项卡片段 class 中的其他视图一样,但我的 FAB 只是消失并且重现.
在某种程度上,我希望 FAB 专用于中心选项卡,并且应该固定。
我也尝试在中心 Fragment class 中定义 FAB,但它似乎没有任何区别。任何意见和建议都会非常有帮助。提前致谢
此库将其视图添加到 'android.R.id.content' ViewGroup。这就是为什么在哪里定义它并不重要。
动画这样的视图可能很困难,但应该是可能的。您已在手动滑动寻呼机时翻译了 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.
如果您只想在 middle/single 选项卡中显示 FloatingActionButton,那么您可以在 Fragment 中添加 FAB,而不是在添加了所有 Fragment 的 Activity 中添加它。
让我简要介绍一下我的想法和我想要实现的目标,
想法是有一个包含三个选项卡的滑动选项卡,每个选项卡屏幕由一个单独的片段表示 class。我使用 "it.neokree:MaterialTabs:0.11" 库完成了此操作,并且一切正常。 然后我使用 "com.oguzdev:CircularFloatingActionMenu:1.0.2" 库创建了一个浮动操作按钮 (FAB)。
现在 我想要实现的是将此 FAB 固定到中心选项卡中的片段,当我滑动屏幕以转到上一个或下一个选项卡时,FAB 应该一起滑出标签片段在其中,当我滑回它时,应该会与中心标签屏幕一起滑回。
到目前为止我一直在研究它,现在我可以在其他片段中隐藏视图并通过重写每个片段中的 setUserVisibleHint()
方法在中心片段中再次显示它 class 就像这个。
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
View tempView = getActivity().findViewById(R.id.myFAB);
tempView.setVisibility(View.INVISIBLE);
}
}
但问题是我希望 FAB 与中心选项卡一起滑出和滑入,就像选项卡片段 class 中的其他视图一样,但我的 FAB 只是消失并且重现.
在某种程度上,我希望 FAB 专用于中心选项卡,并且应该固定。
我也尝试在中心 Fragment class 中定义 FAB,但它似乎没有任何区别。任何意见和建议都会非常有帮助。提前致谢
此库将其视图添加到 'android.R.id.content' ViewGroup。这就是为什么在哪里定义它并不重要。
动画这样的视图可能很困难,但应该是可能的。您已在手动滑动寻呼机时翻译了 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.
如果您只想在 middle/single 选项卡中显示 FloatingActionButton,那么您可以在 Fragment 中添加 FAB,而不是在添加了所有 Fragment 的 Activity 中添加它。