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?
I tried to wrap it into another 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.
I also tried it with a LinearLayout or RelativeLayout instead but then the FloatingActionButton wasn't be placed correctly.
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. I added the FloatingActionButton inside the content layout but it didn't work correctly when Snackbar slide up.
I tried using https://github.com/natario1/NestedScrollCoordinatorLayout but it didn't work for me. Solution for me is to add the FloatingActionButton programmatically to the root CoordinatorLayout. Then it's a direct child of CoordinatorLayout and works correctly. Didn't find a solution where i can have nested CoordinatorLayout which work correctly.
Related
I have a layout hierarchy like this:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<LinearLayout>
//Conteiner with some other views. I want to hide this section on scrall.
</LinearLayout>
<TabLayout/> // I want to make this TabLayout like sticky header on scroll.
<ViewPager/> // Recycler inside
</CoordinatorLayout>
I think I can do it by pitting the content container and tab layout as different VIewHolders into the recyclerView. And then add some Item decoration to make the tab layout sticky. But I think it is I can achieve such behavior using the Coordinator layout. I will appreciate any suggestions
I have got three Constraint Layout inside a Master Constraint Layout which is inside a Scroll View.
So basically the structure is like:
<NestedScrollView>
<ConstraintLayout>
<ConstraintLayout>
</ConstraintLayout>
<ConstraintLayout>
</ConstraintLayout>
<ConstraintLayout>
</ConstraintLayout>
</ConstraintLayout>
</NestedScrollView>
This is just to give an idea of the structure. I need a floating action button to be visible at the bottom of the screen through out the scroll view. Just like in the image below. How do i achieve it?
DrawerLayout is not visible if I use constraintLayout as root layout it still opens and closes, but it's not visible. It works if I make drawerLayout as root or another layout like RelativeLayout or LinearLayout. Any idea why that is happening?
This doesn't work
<ConstraintLayout>
<DrawerLayout>
These works
<DrawerLayout>
<ConstraintLayout>
<LinearLayout>
<DrawerLayout>
<RelativeLayout>
<DrawerLayout>
DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.
That's why you can't make it as child to other ViewGroups.
Check reference here
By default, CollapsingToolbarLayout is being collapsed or expanded when user scrolls the view from NestedScrollView.
How can I turn off auto expanding? What I want to achieve is a toolbar which I can expand or collapse only by calling AppBarLayout::setExpanded.
OK, I've found an answer. In order to make toolbar collapsing on the screen scrolled, we have to create following layout hierarchy:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<Toolbar />
</CollapsingToolbarLayout>
</AppBarLayout>
<NestedScrollView>
<!-- content -->
</NestedScrollView>
</CoordinatorLayout>
In order to turn off this feature (to make scrolling not cause collapsing the toolbar), we have just to replace NestedScrollView with ScrollView.
I have a problem with the below layout structure:
<CoordinatorLayout>
<AppBarLayout>
<Toolbar>
</AppBarLayout>
<DrawerLayout
app:layout_behavior="appbarScrollingBehavior">
<ViewPager>
<ListView>
</DrawerLayout>
</CoordinatorLayout>
Everything works fine, but there is a problem with the scrolling of the AppBarLayout. Namely, the ListView acting as a side drawer is "pushed" downwards by the height of the Toolbar. This causes the last element to be visible only when the Toolbar is completely collapsed :-(
Any ideas why this is happening? I already tried replacing the ListView with a RecyclerView, but it did not help. It seems that the CoordinatorLayout is measuring children first and only then moving them according to the Behaviors.