I have a FrameLayout
inside CoordinatorLayout
to inflate my fragments which contain RecyclerView
. The thing is, I want to display a progress bar when loading the RecyclerView
, but the progress bar is always at the top of the screen under the Toolbar
. I have tried various layouts, setting gravity
or centerInParent
but none had worked. So is there any way to achieve this?
Put the progress bar inside the CoordinatorLayout with android:layout_gravity="center" .
To center a view, just drag the handles to all four sides of the parent.
We can align a view in center of the FrameLayout by setting the layout_gravity of the child view.
CoordinatorLayout is a super-powered FrameLayout . CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout. As a container for a specific interaction with one or more child views.
At the Google I/O 2015, Google introduced Coordinator Layout to remove the difficulties of having more than one layouts in FrameLayout. Now, with the help of the CoordinatorLayout, the interaction between the views become very easy even in the case of animation.
The Coordinator Layout is described as a “ a super-powered FrameLayout” according to the docs. It is used to facilitate how views within your layout interact with each other. This is done by creating or assigning specific Behaviors to these views.
CoordinatorLayout works by searching through any child view that has a CoordinatorLayout Behavior defined either statically as XML with a app:layout_behavior tag or programmatically with the View class annotated with the @DefaultBehavior decorator.
Note: AppBarLayout currently expects to be the direct child nested within a CoordinatorLayout according to the official Google docs. Next, we need to define an association between the AppBarLayout and the View that will be scrolled. Add an app:layout_behavior to a RecyclerView or any other View capable of nested scrolling such as NestedScrollView.
android:layout_gravity="center"
works just fine. And remove your FrameLayout, it's redundant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With