[英]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.