Floating action button in Constraint Layout - android

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?

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

How can i achieve a viewpager for a certain portion of my screen?

I want to achieve a horizontal scroll view for a linear layout. I thought of doing this using viewpager but i am not able to figure out how?
Layout I want to achieve:
You need to take 2 FrameLayouts inside your parent linear layout and inside of the frame layout add your view pager. Something like below,
<FrameLayout>
<ViewPager/>
</FrameLayout>
<FrameLayout>
<ViewPager/>
</FrameLayout>
</LinearLayout>

Recyclerview items invisible/ Missing when keyboard is visible

Problem :
My recyclerview item have one edittext.
If user edit the edittext -> Keyboard will appear & some list items missing. (means recyclerview shrink when keyboard open after keyboard close shrinked recyclerview not expanded)
My xml design
<ScrollView>
<ConstraintLayout>
<other views>
<recyclerview/>
</ConstraintLayout>
</ScrollView>
Manifest activity windowSoftInputMode
android:windowSoftInputMode="adjustPan"
Tried lot of google & SO. But no luck. Anyone give me solution. If anyone need more info let me know. I will give more details.
UPDATE:
My xml code - https://pastebin.com/diz4t9mp
My issue - Video reference
https://drive.google.com/file/d/15J4hOnCM7Gu6uvklhzlSSD7XUCmmGmzg/view?usp=sharing
Change this
<ScrollView>
<ConstraintLayout>
<other views>
<recyclerview/>
</ConstraintLayout>
</ScrollView>
to
<android.support.v4.widget.NestedScrollView>
<ConstraintLayout>
<other views>
<recyclerview/>
</ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
NestedScrollView is used when there is a need for a scrolling view
inside another scrolling view. Normally this would be difficult to
accomplish since the system would be unable to decide which view to
scroll , it supports acting as both a nested scrolling parent and child on both new and old versions of Android.

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.

Categories

Resources