自定义View之极简流式布局

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; jgetWidth()){
                leftMargin=0;
                topMargin+=measureHeight;
            }
            getChildAt(j).layout(leftMargin,topMargin,measuredWidth+leftMargin,measureHeight+topMargin);
            leftMargin+=measuredWidth;
        }
    }
}

你可能感兴趣的:(开发)