其他分享
首页 > 其他分享> > 4.关于View的绘制 (中):layout

4.关于View的绘制 (中):layout

作者:互联网

1.Layout过程

  1. View的layout
    view的layout方法用来确定view本身的位置
public void layout(int l, int t, int r, int b) {
	...
}
/**
     * Called from layout when this view should
     * assign a size and position to each of its children.
     *
     * Derived classes with children should override
     * this method and call layout on each of
     * their children.
     * @param changed This is a new size or position for this view
     * @param left Left position, relative to parent
     * @param top Top position, relative to parent
     * @param right Right position, relative to parent
     * @param bottom Bottom position, relative to parent
     */
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    }
  1. ViewGroup的layout
    确定所有子元素的位置
    @Override
    public final void layout(int l, int t, int r, int b) {
        if (!mSuppressLayout && (mTransition == null || !mTransition.isChangingLayout())) {
            if (mTransition != null) {
                mTransition.layoutChange(this);
            }
            super.layout(l, t, r, b);
        } else {
            // record the fact that we noop'd it; request layout when transition finishes
            mLayoutCalledWhileSuppressed = true;
        }
    }
    @Override
    protected abstract void onLayout(boolean changed,
            int l, int t, int r, int b);

3.总结

wei.zheng 发布了37 篇原创文章 · 获赞 0 · 访问量 547 私信 关注

标签:layout,int,param,onLayout,position,绘制,View
来源: https://blog.csdn.net/qq_37514242/article/details/104445619