Skip to content

@guliash & Artem Gilmudinov - #7

Open
guliash wants to merge 5 commits into
yamblz-native:masterfrom
guliash:master
Open

@guliash & Artem Gilmudinov#7
guliash wants to merge 5 commits into
yamblz-native:masterfrom
guliash:master

Conversation

@guliash

@guliash guliash commented Jul 17, 2016

Copy link
Copy Markdown

Horizontal Linear Layout.

  • Considers its own paddings.
  • Doesn't consider children margins and paddings (because ViewGroup.LayoutParams is used).
  • fragment_content.xml contains an example of using.

@guliash

guliash commented Jul 21, 2016

Copy link
Copy Markdown
Author

device-2016-07-21-160506
Красный match_parent, чёрный 100dp, последний столбец wrap.

}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

неправильно считается высота, если задать HorizontalLinearLayout wrap_parent, то некоторые вьюхи схлопнуться

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

так же и с шириной

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

По поводу твоих замечаний.
Я сейчас задумался. Такой кейс. Пусть этот вью груп wrap_conent. В нём много вьюх с высотой match_parent, вьюха с шириной match_parent и высотой wrap_content, и много вьюх с высотой wrap_content и fixed(dp). Я не могу посчитать высоту вьюх match_parent пока не посчитаю высоты вьюх с fixed и wrap_content. В то же время я не могу посчитать ширину вьюхи с match_parent, пока не посчитаю ширину остальных вьюх. Получается, что я не могу посчитать суммарные размеры без замера какой-то вьюхи дважды. Но это же противоречит ТЗ(что measure надо делать в один проход)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Я не могу посчитать высоту вьюх match_parent пока не посчитаю высоты вьюх с fixed и wrap_content.

Высота уже есть в measureSpec, точнее ограничения по высоте.
Что-то я не очень понял как ты связал расчет высоты и ширины: они же не зависят друг от друга.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Родитель контейнера почти наверняка передаст AT_MOST.
Чтобы посчитать ширину единственной вьюхи с шириной match_parent надо вычислить ширины всех остальных. Чтобы посчитать высоты всех вьюх с высотой match_parent надо посчитать высоты всех вьюх с wrap_content и fixed и выставить вьюхам с match_parent max от тех. Пусть у нас есть вьюха с шириной match_parent и высотой wrap_content (назовём её A). Вьюхи с высотой match_parent не могут посчитаться пока не посчитается высота A. С другой стороны ширина A не может посчитаться пока не посчитаются ширины всех остальных вьюх. Таким образом одно зависит от другого и что-то придётся посчитать дважды (например A, тогда станет известна её высота и мы можем выставить высоты вьюхам с высотой match_parent).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А, понял про что ты, верно, но это нельзя считать один лишний meause это уже 2 прохода, 2 прохода это когда 2 цикла.

@bracadabra bracadabra Aug 11, 2016

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Можно еще посмотреть, если интересно, как сделано во FrameLayout, там хранится список mMatchParentChildren в который добавляются все элементы с match_parent и в конце есть еще один проход по этому списке с выставлением правильно высоты/ширины. Тебе, конечно, так делать не надо. Просто у тебя при выставлении в wrap_content вьюхи совсем обрезались, так точно не должно быть)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Да, так быть не должно. Ок, если можно заюзать лишний measure то easy. Сделаю.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Сделано. В худшем случае нужно childCount + 1 measure детей.

Copy link
Copy Markdown
Collaborator

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants