How to display grid of images (GridLayout) in Harmony OS?

Viewed 111

I am trying to use TableLayoutManager, to display images in grid view, in ListContainer. But, it is not displaying in the form of a grid of images, but, is displaying a list of images. For Eg code used is added below,

ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_recyclerView);
TableLayoutManager tableLayoutManager = new TableLayoutManager();
tableLayoutManager.setOrientation(Component.VERTICAL);
tableLayoutManager.setColumnCount(3);
listContainer.setLayoutManager(tableLayoutManager);

Can you please inform, what is the issue in the above code, and how can we achieve a grid of images/items, in Harmony OS.

3 Answers

Thanks for your feedback. As confirmed by the team, currently, TableLayoutManager is not supported in ListContainer. And grid of images (GridLayout) function is aslo not supported by now. Please stay tuned on HarmonyOS official websites.

Based on the documentation from the HarmonyOS developer website, I think that you will need to set both the amount of columns and rows that you want. https://developer.harmonyos.com/en/docs/documentation/doc-guides/ui-java-layout-tablelayout-0000001060379893

Component component = findComponentById(ResourceTable.Id_text_one);
TableLayout.LayoutConfig tlc = new TableLayout.LayoutConfig(vp2px(72), vp2px(72));
tlc.columnSpec = TableLayout.specification(TableLayout.DEFAULT, 2);
tlc.rowSpec = TableLayout.specification(TableLayout.DEFAULT, 2);
component.setLayoutConfig(tlc);
Related