onMeasure方法中:
measureChildren(widthMeasureSpec, heightMeasureSpec);
必须重写onLayout方法中:
@Override protected void onLayout(boolean b, int i, int i1, int i2, int i3) { int childCount = getChildCount(); for(int y=0;y<childCount;y++){ int k = 0; int l = 0; View childAt = getChildAt(y); childAt.layout(k,l,200,150); //定位 int measuredHeight = childAt.getMeasuredHeight(); int measuredWidth = childAt.getMeasuredWidth(); k+=measuredWidth; l+=measuredHeight; } }