evrencoskun / TableView

TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
MIT License
3.14k stars 459 forks source link

How to set column width match the screen width? #204

Open ghost opened 5 years ago

ghost commented 5 years ago

How to set column width match the screen width?

ChaoquanTao commented 5 years ago

any progress bro?I met the same problem

ronnie173 commented 5 years ago

I am trying to figure this out also

TheRealChrisThomas commented 5 years ago

Fair warning. I'm still getting familiar with this view.

I was able to get 1 column to take up the whole screen by adding this into my ColumnHeaderViewHolder class inside setColumnHeaderModel:

column_header_container.layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT
column_header_textview.requestLayout()

Then inside my CellHolder inside function setCellModel:

cell_container.layoutParams.width= MATCH_PARENT 
cell_textView.requestLayout()

This is assuming that your Table View has a layout_width of match_parent

naitbrahim commented 5 years ago

If you want to give a certain width to every column, you can calculate the width of the device then you do a division by the numbers of columns so they can fit the whole screen width.

egeysn commented 3 years ago

While i using to table with four header it was not covering the page.I solved this problem following methods. Optional(I hide the all row items in the table) - binding.myTableView.setAdapter(mTableAdapter); binding.myTableView.setRowHeaderWidth(0); in MyTableViewAdapter:

public MyTableViewAdapter(Context context, int size) { // size :: for dynamic header items
    mContext = context;
    screenWidth = utils.getScreenWidth();
    headerWidth = (int) (screenWidth / size);
}

later i sent header width to Header


public ColumnHeaderViewHolder(TableviewColumnHeaderLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
        public void setColumnHeaderModel(ColumnHeaderModel key, int pColumnPosition) {
            // Set text data
            binding.columnHeaderTextView.setText(key.getData());
            //   binding.columnHeaderContainer.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT; 
              i changed this code to this-->
            binding.columnHeaderContainer.getLayoutParams().width = headerWidth;
            binding.columnHeaderTextView.requestLayout();
        }

OK , nice works :)