网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

自定义ViewDemo

public class VerticalOffsetLayout extends ViewGroup {

公司主营业务:网站设计制作、网站设计、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联公司推出福贡免费做网站回馈大家。

private static final int OFFSET = 100;
private Paint mPaint;

public VerticalOffsetLayout(Context context) {
    super(context);
    init(context, null, 0);
}

public VerticalOffsetLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context, attrs, 0);
}

public VerticalOffsetLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init(context, attrs, defStyleAttr);
}

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    mPaint = new Paint(Color.BLUE);
    mPaint.setAntiAlias(true);
    mPaint.setAlpha(125);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    int width = 0;
    int height = 0;

    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        ViewGroup.LayoutParams lp = child.getLayoutParams();
        int childWidthSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
        int childHeightSpec = getChildMeasureSpec(heightMeasureSpec, 0, lp.height);
        child.measure(childWidthSpec, childHeightSpec);
    }

    switch (widthMode) {
        case MeasureSpec.EXACTLY:
            width = widthSize;
            break;
        case MeasureSpec.AT_MOST:
        case MeasureSpec.UNSPECIFIED:
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                int widthAddOffset = i * OFFSET + child.getMeasuredWidth();
                width = Math.max(width, widthAddOffset);
            }
            break;
        default:
            break;

    }

    switch (heightMode) {
        case MeasureSpec.EXACTLY:
            height = heightSize;
            break;
        case MeasureSpec.AT_MOST:
        case MeasureSpec.UNSPECIFIED:
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                height = height + child.getMeasuredHeight();
            }
            break;
        default:
            break;

    }

    setMeasuredDimension(width, height);
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int left = 0;
    int right = 0;
    int top = 0;
    int bottom = 0;

    int childCount = getChildCount();

    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        left = i * OFFSET;
        right = left + child.getMeasuredWidth();
        bottom = top + child.getMeasuredHeight();

        child.layout(left, top, right, bottom);

        top += child.getMeasuredHeight();
    }
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int x = getWidth()/2;
    int y = getHeight()/2;
    canvas.drawCircle(x, y, Math.min(x, y), mPaint);
}

}


当前标题:自定义ViewDemo
当前路径:http://bjjierui.cn/article/gsesge.html

其他资讯