1

我尝试在我的库中导入一些 android 内部源代码。但是我在导入这部分代码时遇到了一些麻烦:

    private final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer =
            new ViewTreeObserver.OnComputeInternalInsetsListener() {
                public void onComputeInternalInsets(
                        ViewTreeObserver.InternalInsetsInfo info) {
                    info.contentInsets.setEmpty();
                    info.visibleInsets.setEmpty();
                    info.touchableRegion.set(mTouchableRegion);
                    info.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo
                            .TOUCHABLE_INSETS_REGION);
                }
            };

这是因为在 ViewTreeObserver.java OnComputeInternalInsetsListener 被声明为隐藏

/**
 * Interface definition for a callback to be invoked when layout has
 * completed and the client can compute its interior insets.
 * 
 * We are not yet ready to commit to this API and support it, so
 * @hide
 */
public interface OnComputeInternalInsetsListener {
    /**
     * Callback method to be invoked when layout has completed and the
     * client can compute its interior insets.
     *
     * @param inoutInfo Should be filled in by the implementation with
     * the information about the insets of the window.  This is called
     * with whatever values the previous OnComputeInternalInsetsListener
     * returned, if there are multiple such listeners in the window.
     */
    public void onComputeInternalInsets(InternalInsetsInfo inoutInfo);
} 

后来我像这样使用它

    /**
     * Make the touchable area of this popup be the area specified by mTouchableRegion.
     * This should be called after the popup window has been dismissed (dismiss/hide)
     * and is probably being re-shown with a new content root view.
     */
    private void setTouchableSurfaceInsetsComputer() {

        ViewTreeObserver viewTreeObserver = mPopupWindow.getContentView()
                .getRootView()
                .getViewTreeObserver();
        viewTreeObserver.removeOnComputeInternalInsetsListener(mInsetsComputer);
        viewTreeObserver.addOnComputeInternalInsetsListener(mInsetsComputer);

    }

所以我可以用什么来代替ViewTreeObserver.OnComputeInternalInsetsListenerremoveOnComputeInternalInsetsListeneraddOnComputeInternalInsetsListener?我什至不知道这些功能的目的......

4

0 回答 0