SmartTable展示数组数据

这段代码展示了如何在Android应用中创建一个智能表格。它使用了SmartTable类和ArrayTableData来填充数据,并实现了自定义的绘制格式,包括单元格的宽高测量和文字绘制。同时,为表格的标题和内容背景设置了不同的颜色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class MainActivity extends AppCompatActivity {

    private SmartTable<String> table;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        table = findViewById(R.id.table);

        String[] week = {"日", "一", "二", "三", "四", "五", "六"};

        String[][] strings = {{"日", "一", "二", "三", "四", "五", "六"}, {"日", "一", "二", "三", "四", "五", "六"},
                {"日", "一", "二", "三", "四", "五", "六"}};

        ArrayTableData<String> data = ArrayTableData.create("日程表", week,
                ArrayTableData.transformColumnArray(strings),
                new IDrawFormat<String>() {
                    @Override
                    public int measureWidth(Column<String> column, int position, TableConfig config) {
                        return 100;
                    }

                    @Override
                    public int measureHeight(Column<String> column, int position, TableConfig config) {
                        return 100;
                    }

                    @Override
                    public void draw(Canvas c, Rect rect, CellInfo<String> cellInfo, TableConfig config) {
                        Paint paint = config.getPaint();
                        paint.setTypeface(Typeface.DEFAULT_BOLD);
                        paint.setStyle(Paint.Style.FILL);
                        paint.setColor(Color.parseColor("#000000"));
                        c.drawText(cellInfo.value, rect.centerX(), rect.centerY()+10, paint);
                    }
                });

        table.getConfig().setColumnTitleBackground(new IBackgroundFormat() {
            @Override
            public void drawBackground(Canvas canvas, Rect rect, Paint paint) {
                canvas.drawColor(Color.parseColor("#999999"));
            }
        });
        table.getConfig().setContentBackground(new IBackgroundFormat() {
            @Override
            public void drawBackground(Canvas canvas, Rect rect, Paint paint) {
                canvas.drawColor(Color.parseColor("#ffffff"));
            }
        });

        table.setTableData(data);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值