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

Column and Cell width desynchronization #191

Closed vkhaitan closed 5 years ago

vkhaitan commented 5 years ago

I am using this UI Element through Xamarin.Android . I ported it myself.

There is an issue which I am facing. setHasFixedSize() makes column and cell desynchronized. Columns has different width, cells have different width. So it becomes zigzag. In fact, all the cells in a column are of different width. I am also using RemeasureColumnWidth() .

This is the offending code - this.HasFixedWidth = true; // Removing this line fixes the issue. for (int i = 0; i < columnData.Count; ++i) { RemeasureColumnWidth(i); } Why would you allow cell to be desynchronized, it simply baffles me.

save
vkhaitan commented 5 years ago

I was trying to solve an issue that after changing the content of Table, I remeaserwidth and it works fine with content hugging width. However, Once I start scrolling, its width change after 1 row scroll. The new width is equal to the largest width table acquired in its existence(which means maximum width during data changes). Why so ?

vkhaitan commented 5 years ago

I tried everything I could, but this cell width resize is still happening. Because of RemeasureWidth(), cell is resizing to fit requirements. However, during scroll its size increases to equal historical maximum size. How does TableView remember what was historical maximum size of TableView Column ?

evrencoskun commented 5 years ago

Hi @vkhaitan,

Why do you need to use setHasFixedSize() ?, You shouldn't use the method which is for some performance control on RecyclerView. However, in TableView the size is not fixed. so you shouldn't use that. Please check this.

In TableView, The proper width value for each column is stored in TableView to be ready for new calculation at vertical scrolling process.

If you want to know, what's going on in the process, please check, ColumnWidthHandler, CellLayoutManager

vkhaitan commented 5 years ago
if (childLayoutManager.isNeedFit()) {

                // Scrolling up
                if (mLastDy < 0) {
                    Log.e(LOG_TAG, position + " fitWidthSize all vertically up");
                    fitWidthSize(true);
                } else {
                    // Scrolling down
                    Log.e(LOG_TAG, position + " fitWidthSize all vertically down");
                    fitWidthSize(false);
                }
                // all columns have been fitted.
                childLayoutManager.clearNeedFit();
            }

This function snippet is being called. Why isNeedFit() is true since I have already measuredProper columnWidth() ? My RemeasureColumnWidth() properly measures and gives correct width. However, during vertical scroll, aforementioned function is called and it gives historical maximum size. RemeasureColumnWidth() already removes cache, so that can't be issue. So, why it gets historical size and how ? I mean if old content is not present, they how does it get the old width ?

vkhaitan commented 5 years ago

Okay, I found that my issue is fixed in issue 169 . So now scrolling is properly working without wrong width.