ArtViewGroup.java 文件源码

java
阅读 37 收藏 0 点赞 0 评论 0

项目:ascii_generate 作者:
public void create(int row, int col) {
    removeAllViews();

    int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
            getResources().getDisplayMetrics());


    this.row = row;
    this.col = col;
    @IdRes int id = 1;
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            ArtTextView artTextView = new ArtTextView(getContext());
            LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            artTextView.setId(id);
            artTextView.setText(Char.SPACE);
            if (j == 0) {
                params.addRule(ALIGN_PARENT_LEFT, TRUE);
            } else {
                params.addRule(RIGHT_OF, id - 1);
            }
            if (i == 0) {
                params.addRule(ALIGN_PARENT_TOP, TRUE);
            } else {
                params.addRule(BELOW, id - col);
            }
            params.setMargins(margin, 0, margin, 0);
            artTextView.setLayoutParams(params);
            addView(artTextView);
            id++;
        }
    }

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号