Android layout - How to implement a fixed/freezed header and column

前端 未结 7 1456
轮回少年
轮回少年 2020-12-24 07:46

I would like to create a table-like view that contains a large number of columns (7-10) while the headers row is always visible (even when scrolling down) and the first colu

7条回答
  •  我在风中等你
    2020-12-24 08:29

    Create TableLayout that will be a header and under it place a Table itself within a ScrollView like this:

    
    
        
            
        
    

    When you will populate your header with data add next code:

    table.post(new Runnable() {
            @Override
            public void run() {
                TableRow tableRow = (TableRow)table.getChildAt(0);
                for(int i = 0; i < headerRow.getChildCount(); i++){
                    headerRow.getChildAt(i).setLayoutParams(new TableRow.LayoutParams(tableRow.getChildAt(i).getMeasuredWidth(), tableRow.getChildAt(i).getMeasuredHeight()));
                }
            }
        });
    

    That's it.

提交回复
热议问题