简体   繁体   English

浮动动作按钮+小吃栏的容器

[英]Container for Floating Action Button + Snackbar

I have this hierarchy: 我有这个层次结构:

<CoordinatorLayout>
  <Framelayout/>
  <NestedScrollView>
    <LinearLayout>
      <FrameLayout/>
    </LinearLayout>
  </NestedScrollView>
  <FloatingActionButton>
</CoordinatorLayout>

I call my snackbar with the root view. 我用根视图称我的快餐吧。 With this layout my snackbar works perfectly as i wanted. 通过这种布局,我的小吃吧可以按我的要求完美地工作。

How can i achieve that i can load the FloatingActionButton dynamically and wrap it into a container? 如何实现可以动态加载FloatingActionButton并将其包装到容器中的方法?

I tried to wrap it into another CoordinatorLayout . 我试图将其包装到另一个CoordinatorLayout So the layout looked like this: 所以布局看起来像这样:

<CoordinatorLayout>
  <Framelayout/>
  <NestedScrollView>
    <LinearLayout>
      <FrameLayout/>
    </LinearLayout>
  </NestedScrollView>
  <CoordinatorLayout> <!-- This is the added container -->
    <FloatingActionButton> <!-- I would like to load it dynamically from another layout file -->
  <CoordinatorLayout>
</CoordinatorLayout>

The problem with this is that when i call my snackbar it overlaps the FloatingActionButton . 问题是当我打电话给我的小吃店时,它与FloatingActionButton重叠。

I also tried it with a LinearLayout or RelativeLayout instead but then the FloatingActionButton wasn't be placed correctly. 我也用LinearLayout或RelativeLayout尝试过,但是FloatingActionButton放置不正确。

In my case i load a content layout inside a class programmatically and don't know on the root layout (the defined xml layout) whether a FloatingActionButton will exist. 在我的情况下,我以编程方式在类内加载了内容布局,并且不知道根布局(定义的xml布局)上是否存在FloatingActionButton I added the FloatingActionButton inside the content layout but it didn't work correctly when Snackbar slide up. 我在内容布局中添加了FloatingActionButton ,但是当Snackbar向上滑动时它无法正常工作。 I tried using https://github.com/natario1/NestedScrollCoordinatorLayout but it didn't work for me. 我尝试使用https://github.com/natario1/NestedScrollCoordinatorLayout,但它对我不起作用。 Solution for me is to add the FloatingActionButton programmatically to the root CoordinatorLayout . 对我来说,解决方案是以编程方式将FloatingActionButton添加到根CoordinatorLayout Then it's a direct child of CoordinatorLayout and works correctly. 然后,它是CoordinatorLayout的直接子级,并且可以正常工作。 Didn't find a solution where i can have nested CoordinatorLayout which work correctly. 找不到可以嵌套的CoordinatorLayout正常工作的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Snackbar在按下动作按钮时隐藏了浮动动作 - Snackbar hides the Floating Action on pressing the action button on it 浮动动作按钮在第二个Snackbar下消失 - Floating Action Button diasappears under SECOND Snackbar Snackbar顶部的浮动动作按钮。 怎么样? - Floating Action Button on top of Snackbar. How? 带有多行的浮动操作按钮 Snackbar - Floating Action Button Snackbar with multi line 如果在 CoordinatorLayout 中设置了 anchorView,则浮动操作按钮不会随 Snackbar 一起浮动 - Floating Action Button Not Floating With Snackbar If anchorView set within CoordinatorLayout 浮动操作按钮不会停留在SnackBar的顶部 - Floating Action Button won't stay on top of SnackBar Snackbar 通过片段导航重叠浮动操作按钮 - Snackbar Overlapping Floating Action Button Through Fragment Navigation Android底部工作表,带有带有Snackbar问题的浮动操作按钮 - Android Bottom Sheet with Floating Action Button with Snackbar Issue 上下移动浮动操作按钮以避免被快餐栏阻挡 - Moving Floating Action Button up and down to avoid getting blocked by a snackbar 当snackbar animation 开始时浮动动作按钮上下跳跃 - Floating Action Button jumps up and down when snackbar animation begins
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM