Skip to content

Comments

HW 8#4

Open
Kaizer22 wants to merge 4 commits intoOtus-Android:masterfrom
Kaizer22:master
Open

HW 8#4
Kaizer22 wants to merge 4 commits intoOtus-Android:masterfrom
Kaizer22:master

Conversation

@Kaizer22
Copy link

@Kaizer22 Kaizer22 commented May 5, 2025

image

content = content,
) { measurables, constraints ->
val itemsCount = measurables.size
val rows = itemsCount / columns +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно было бы проверить columns на 0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил проверку columns на 0

Comment on lines 59 to 60
x = heigh * j,
y = width * i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь не перепутаны heigh и width местами?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправил

content()
content = content,
) { measurables, constraints ->
val itemsCount = measurables.size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь тоже проверку на 0 можно. Или как-то обойти.
Если measurables.size = 0, т.е. нет элементов, то itemsCount будет = 0. И значит rows = 0.

А ниже мы делим на rows (на 0)
val maxHeight = constraints.maxHeight / rows

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил проверку measurables.size = 0, в этом случае вызываем layout(0, 0, {})

Comment on lines 39 to 42
Constraints(
maxWidth = maxWidth,
maxHeight = maxHeight,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь в цикле создаем объект Constraints каждый раз. Чуть эффективнее будет если его вынесем снаружи цикла. Тем более что он одинаковый и не меняется.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вынес из цикла

Comment on lines 39 to 42
Constraints(
maxWidth = maxWidth,
maxHeight = maxHeight,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Еще для читаемости для Constraints можно задать min значения в 0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants