首页 > 解决方案 > 如何将自定义布局用作表格布局中的视图

问题描述

我有一个布局,我想将其用作 TableLayout 中的元素。我试图将布局膨胀为视图,然后将它们添加到 TabelRow 中。由于某种原因它不起作用,我无法弄清楚为什么或如何解决它。

        LayoutInflater inflater = LayoutInflater.from(this);
        TableLayout sudokuGrid = (TableLayout) findViewById(R.id.sudokuGrid);
        TableRow tableRow = new TableRow(this);
        View cell = inflater.inflate(R.layout.cell_layout, null);
        tableRow.addView(cell);
        sudokuGrid.addView(tableRow);

标签: javaandroidandroid-layout

解决方案


推荐阅读