3

While creating a Layout, I cam across FitWindowsLinearLayout but can't seem to understand the difference between LinearLayout and FitWindowsLinearLayout.

So, when should we use FitWindowsLinearLayout?

FitWindowsLinearLayout

Ghulam Moinul Quadir
  • 1,638
  • 1
  • 12
  • 17
Suraj Makhija
  • 1,376
  • 8
  • 16

1 Answers1

3

First, as you can see it is annotated with @hide, which means, that it is not exposed to public API. That means that you should not use it.

Secondly, to answer your question: as you can see from the implementation, it has one public method, which sets a listener:


    public void setOnFitSystemWindowsListener(OnFitSystemWindowsListener listener) {
        mListener = listener;
    }

And this listener would be called when fitSystemWindows(Rect) is called:


    @Override
    protected boolean fitSystemWindows(Rect insets) {
        if (mListener != null) {
            mListener.onFitSystemWindows(insets);
        }
        return super.fitSystemWindows(insets);
    }

This means, that you can retrieve Rect insets following way:


    FitWindowsLinearLayout layout = new FitWindowsLinearLayout(context);

    layout.setOnFitSystemWindowsListener(new OnFitSystemWindowsListener() {
        boolean onFitSystemWindows(Rect insets) {
            // interact with `insets`
            return true;
        }
    })

To know what are insets see this explanation.

azizbekian
  • 60,783
  • 13
  • 169
  • 249