レイアウトに 2 つのビューがあります。View A
それぞれと と呼びますView B
。
┌──────┐
│┌─┐┌─┐│
││A││B││
│└─┘└─┘│
└──────┘
親レイアウト ( と を含む) の高さView A
はView B
ですWRAP_CONTENT
。
ここで、 の高さはView B
ですWRAP_CONTENT
。つまり、内容に応じて高さを変更できます。
私がやりたいことは
- のコンテンツが のコンテンツよりも短い場合、 の
View A
高さを の高さに設定します。View B
View A
View B
- のコンテンツが のコンテンツよりも高い
View A
場合、 の高さを独自のコンテンツの高さに設定します。View A
View B
そう、
① のコンテンツのView B
方が高ければ、View A
の高さは の高さに設定されView B
ます。
┌──────┐ ┌──────┐
│┌─┐┌─┐│ │┌─┐┌─┐│
││ ││ ││ ││A││ ││
I want ││A││B││, not │└─┘│B││.
││ ││ ││ │ │ ││
│└─┘└─┘│ │ └─┘│
└──────┘ └──────┘
② のコンテンツView B
が短い場合、View A
の高さはView A
自身のコンテンツの高さになります。
┌──────┐ ┌──────┐
│┌─┐┌─┐│ │┌─┐┌─┐│
││ ││B││ ││A││B││
I want ││A│└─┘│, not │└─┘└─┘│.
││ │ │ └──────┘
│└─┘ │
└──────┘
親が の場合、の高さを に設定するとケース 1 にLinearLayout (Horizontal)
違反し、の高さをに設定するとケース 2 に違反します。View A
WRAP_CONTENT
View A
MATCH_PARENT
親が の場合、親の上と下の両方を揃えるRelativeLayout
設定はの条件に違反します。View A
RelativeLayout
Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM.
どうすればこの問題を解決できますか?