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
Related
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?
I want to use the collapsing toolbar layout inside the sliding up panel as its child. When expanded could be able to also expand and collapse the collapsing toolbar.
Note: Sliding up panel https://github.com/umano/AndroidSlidingUpPanel
Edit:
I want to achieve this
<SlidingUpPanel>
-CHILD 1 main content
-child 2 fragment
</SlidingUpPanel>
Now in the fragment
<coordinatorLayout>
<appbarlayout>
<collapsingToolBarLayout>
<ImageView/>
<ToolBar/>
</collapsingToolBarLayout>
</appBar>
<ListView behaviour='scrollingview' />
</coordinatorLayout>
The problem is when the collapsing layout is expanded and when i try to collapse it the collapses the sliding up panel instead of the collapsing layout.
How can i fix it??
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 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.
I have an activity where CollapsingToolbarLayout is combined with ViewPager.
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView />
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<CardView>
<LinearLayout>
<TabLayout/>
<ViewPager/>
</LinearLayout>
</CardView>
</CoordinatorLayout>
ViewPager contains pages with NastedScrollViews or RecyclerViews. Everything works well except when I scroll content of ViewPager up/down and CollapsingToolbarLayout is in the middle of collapsing or expanding and finger slightly moves left or right it interrupts collapsing/expanding and starts to scroll pages.
How do I prevent this ?
I know how to prevent ViewPager from scrolling. But cant figure out how do I subscribe for CollapsingToolbarLayout changes. Or maybe should I listen to CoordinatorLayout ro implement CoordinatorLayout.Behavior that notifies me...
Thanks.