前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >datagridview 自定义格式_word自定义表格

datagridview 自定义格式_word自定义表格

作者头像
全栈程序员站长
发布2022-11-08 16:13:55
4850
发布2022-11-08 16:13:55
举报

大家好,又见面了,我是你们的朋友全栈君。

public class MyGrideView extends GridView { public MyGrideView(Context context) { super(context); }

代码语言:javascript
复制
public MyGrideView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

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

//该自定义控件只是重写了GridView的onMeasure方法,使其不会出现滚动条,ScrollView嵌套ListView也是同样的道理,不再赘述。
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int expandSpec = MeasureSpec.makeMeasureSpec(
            Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, expandSpec);
}

/**
 * 重绘分割线
 */

@Override
protected void dispatchDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.dispatchDraw(canvas);

    View localView1 = getChildAt(0);
    int column = getWidth() / localView1.getWidth();
    int childCount = getChildCount();
    Paint localPaint;
    localPaint = new Paint();
    localPaint.setStyle(Paint.Style.STROKE);
    localPaint.setStrokeWidth(2);
    localPaint.setColor(getContext().getResources().getColor(R.color.gray001));
    for(int i = 0;i < childCount;i++){
        View cellView = getChildAt(i);
        if((i + 1) % column == 0){
            if (i != childCount -1){
                canvas.drawLine(cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), localPaint);
            }
        }else if((i + 1) > (childCount - (childCount % column))){
            canvas.drawLine(cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), localPaint);
        }else{
            canvas.drawLine(cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), localPaint);
            if (i != childCount -2 && i != childCount -3){
                canvas.drawLine(cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), localPaint);
            }
        }
    }
    if(childCount % column != 0){
        for(int j = 0 ;j < (column-childCount % column) ; j++){
            View lastView = getChildAt(childCount - 1);
            canvas.drawLine(lastView.getRight() + lastView.getWidth() * j, lastView.getTop(), lastView.getRight() + lastView.getWidth()* j, lastView.getBottom(), localPaint);
        }
    }
}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年9月24日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档