レイアウトに 2 つのビューがあります。View Aそれぞれと と呼びますView B。
┌──────┐
│┌─┐┌─┐│
││A││B││
│└─┘└─┘│
└──────┘
親レイアウト ( と を含む) の高さView AはView BですWRAP_CONTENT。
ここで、 の高さはView BですWRAP_CONTENT。つまり、内容に応じて高さを変更できます。
私がやりたいことは
- のコンテンツが のコンテンツよりも短い場合、 の
View A高さを の高さに設定します。View BView AView B - のコンテンツが のコンテンツよりも高い
View A場合、 の高さを独自のコンテンツの高さに設定します。View AView 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 AWRAP_CONTENTView AMATCH_PARENT
親が の場合、親の上と下の両方を揃えるRelativeLayout設定はの条件に違反します。View ARelativeLayout
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.
どうすればこの問題を解決できますか?