问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/46987487/what-is-the-difference-between-linearlayout-and-fitwindowslinearlayout