G
G
grogzon2018-07-04 23:45:31
Android
grogzon, 2018-07-04 23:45:31

How to dynamically scale an ImageView inside a GridLayout?

Please help me figure out the dynamic scaling of the ImageViews that are located inside the GridLayout based on the screen size of the device.
There is a top centered Button. Below it, there is a GridLayout for which the number of columns and rows is set by the code (for example, 15x15). Dynamically programmatically, an ImageView is added to each cell, which naturally crawls out of the screen. With the setLayoutParams method , I change the size of the ImageView relative to the screen sizes I get with getWindowManager().getDefaultDisplay().getRealSize() and the grid size. I think like this:

imageViewWidth = screen.x / gridColumns;
imageViewHeight = (screen.y - buttonHeight) / gridRows;

But in the end, for some reason, the width scales normally, but the height is incorrect (example in the picture, where you can see that one row is located under the screen). Tell me what's the problem? Maybe there is a simpler container that will allow you to make such a table that automatically changes the size of the cells? The main goal is to make sure that the table from the ImageView (which is created dynamically by the code) fits completely on the screen, taking into account the fact that other elements (for example, buttons) can still be on top of the grid.
5b3d31817e898829507761.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2018-07-05
@zagayevskiy

GridView is useless in this situation, because its main features are not used here. See TableLayout.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question