import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
/*Time:2018/4/26
*Author:zhaozhiwei
*Description:
*/public class liuView extends ViewGroup {
public liuView(Context context) {
super(context);
}
public liuView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public liuView(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 changed, int l, int t, int r, int b) {
int leftMargin = 0;
int topMargin = 0;
for (int j = 0; j<getChildCount();j++){
int measureHeight = getChildAt(j).getMeasuredHeight();
int measuredWidth = getChildAt(j).getMeasuredWidth();
if (leftMargin+measuredWidth>getWidth()){
leftMargin=0;
topMargin+=measureHeight;
}
getChildAt(j).layout(leftMargin,topMargin,measuredWidth+leftMargin,measureHeight+topMargin);
leftMargin+=measuredWidth;
}
}
}
自定义View之极简流式布局
猜你喜欢
转载自blog.csdn.net/Android_Mr_Zhao/article/details/89552151
今日推荐
周排行