DrawerLayout inside a ConstraintLayout - android

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

Related

Hide view on scroll in a coordinator layout

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

Floating action button in Constraint Layout

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?

Collapse Layout inside ContraintLayout based on view focus or scroll

I am looking into CoordinatorLayout and ConstraintLayout and I want to know if it's possible to achieve something as in :
As you can see my layout, has:
the toolbar which is not affected by this. The toolbar is on the main activity and it's not changed.
under the toolbar there is a fragment loaded with its layout. The layout contains a ImageView at the top, some EditTexts and a RecyclerView
Behavior:
When user taps on the red EditText I want the layout to scroll up, so that the focused EditText is at the top of the screen with the RecyclerView under it.
At any time the user can scroll down and the initial layout gets shown.
My question is: what would be the best way to create this animation and behavior?
I managed to obtain the desired behavior by using in the layout:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<My layout that will get scrolled to the top and be hidden>
</CollapsingToolbarLayout>
<RedEditText which will scroll up until the CollapsingToolbar is collapsed>
</AppBarLayout>
<RecyclerView/>
</CoordinatorLayout>

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?
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.

Scrolling Toolbar in DrawerLayout in CoordinatorLayout

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.

Categories

Resources