public MyView(Context context) {
this(context,null);
}
public MyView(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
measureChildren(widthMeasureSpec,heightMeasureSpec);
}
@Override
protected void onLayout(boolean b, int i, int i1, int i2, int i3) {
int measuredWidth1 = this.getMeasuredWidth();
int startWidth = 0;
int startHight = 0;
int childCount = getChildCount();
for (int k = 0;k<childCount;k++){
View childAt = getChildAt(k);
int measuredWidth = childAt.getMeasuredWidth();
int measuredHeight = childAt.getMeasuredHeight();
childAt.layout(startWidth,startHight,startWidth+measuredWidth,startHight+measuredHeight);
startWidth+=measuredWidth;
if((measuredWidth+startWidth)>measuredWidth1){
startHight+=measuredHeight;
startWidth = 0;
}
}
}
自定义流失布局
最新推荐文章于 2024-04-29 02:32:58 发布