What is the difference between LinearLayout and FitWindowsLinearLayout?

老子叫甜甜 提交于 2020-01-15 03:43:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!