美文网首页
view-CoordinatorLayout

view-CoordinatorLayout

作者: miky_zheng | 来源:发表于2019-02-17 22:39 被阅读0次

    重点:实现了NestedScrollingParent2
    默认支持标题栏的平滑收缩。

    onLayout
      private void layoutChild(View child, int layoutDirection) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            final Rect parent = acquireTempRect();
            parent.set(getPaddingLeft() + lp.leftMargin,
                    getPaddingTop() + lp.topMargin,
                    getWidth() - getPaddingRight() - lp.rightMargin,
                    getHeight() - getPaddingBottom() - lp.bottomMargin);
    
            if (mLastInsets != null && ViewCompat.getFitsSystemWindows(this)
                    && !ViewCompat.getFitsSystemWindows(child)) {
                // If we're set to handle insets but this child isn't, then it has been measured as
                // if there are no insets. We need to lay it out to match.
                parent.left += mLastInsets.getSystemWindowInsetLeft();
                parent.top += mLastInsets.getSystemWindowInsetTop();
                parent.right -= mLastInsets.getSystemWindowInsetRight();
                parent.bottom -= mLastInsets.getSystemWindowInsetBottom();
            }
    
            final Rect out = acquireTempRect();
            GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(),
                    child.getMeasuredHeight(), parent, out, layoutDirection);
            child.layout(out.left, out.top, out.right, out.bottom);
    
            releaseTempRect(parent);
            releaseTempRect(out);
        }
    
        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            final int layoutDirection = ViewCompat.getLayoutDirection(this);
            final int childCount = mDependencySortedChildren.size();
            for (int i = 0; i < childCount; i++) {
                final View child = mDependencySortedChildren.get(i);
                if (child.getVisibility() == GONE) {
                    // If the child is GONE, skip...
                    continue;
                }
    
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                final Behavior behavior = lp.getBehavior();
    
                if (behavior == null || !behavior.onLayoutChild(this, child, layoutDirection)) {
                    onLayoutChild(child, layoutDirection);
                }
            }
        }
    

    相关文章

      网友评论

          本文标题:view-CoordinatorLayout

          本文链接:https://www.haomeiwen.com/subject/qhoneqtx.html