Is it possible to center a layout/view inside CoordinatorLayout?

After some research I failed to find a way to make this work, so in the end I did this:

  1. Put the progress bar inside the CoordinatorLayout with android:layout_gravity="center".
  2. In the activity, make 2 methods to show/hide progress bar:

    public void showProgress() {
          progressBar.setVisibility(View.VISIBLE);
    }
    
    public void hideProgress() {
          progressBar.setVisibility(View.INVISIBLE);
    }
    
  3. In the fragment, get a reference of the above activity through getActivity(), cast it to the actual activity and call the necessary method.

    context = getActivity();
    ((MainActivity)context).showProgress();
    

EDIT: this seems to be fixed in support library 23.1.1


    android:layout_gravity="center" 

works just fine. And remove your FrameLayout, it's redundant.