TableView
TableView copied to clipboard
Layout Bug on Android < API18
I think this is a bug in the Android itself and this is more of documentation of a work around.
If you create a TableView and set as the root view or as a child of a linear Layout either programmatically or via XML layout files on Android Emulators running API less than API 18 then the column header recyclerview does not get sized correctly.
The header column recyclerview is full functional just it size when there is not enough data to fill the screen width is shorter than the data it holds (i.e. the WRAP_CONTENT property on it is not working correctly), you can scroll the header to show all the content.
The fix is use inside of a RelativeLayout
in xml or programmatically.
Example of Bug on API 15 Emulator
Same code on API 18 Emulator
Code from Espresso test used to generate screen shots
`Activity activity = mActivityTestRule.getActivity();
TableView tableView =
new TableView(InstrumentationRegistry.getInstrumentation().getTargetContext());
Assert.assertNotNull(tableView);
SimpleTestAdapter simpleTestAdapter = new SimpleTestAdapter();
Assert.assertNotNull(simpleTestAdapter);
tableView.setAdapter(simpleTestAdapter);
SimpleData simpleData = new SimpleData(5);
simpleTestAdapter.setAllItems(simpleData.getColumnHeaders(), simpleData.getRowHeaders(),
simpleData.getCells());
mActivityTestRule.runOnUiThread(() -> activity.setContentView(tableView));`
I have the same issue on API 29. I don't think it's a size issue of the column header, rather a black rectangle that pops on top of the column header. Clicking on one of the column header makes the rectangle disappear. For me, the rectangle comes up when I refresh the data in the table.
I'll investigate more and try to submit a PR to fix that properly.