如何使RelativeLayout中的child-alignParentRight设置为wrap_content



在设置为wrap_contentRelativeLayout中,子级不能设置为layout_alignParentRight="true"

有什么办法做到这一点吗?


我在这里找到了一个解决方案:[A LinearLayout(垂直)(wrap_content)][B(A的子项)RelativeLayout(match_parent)][D(B的子项)TextView layout_alignParentRight="true"][c(A的子项)TextView->哪个A试图包装]

我知道"A是wrap_content,然后B是match_parent"是不好的,但不知何故它是有效的。

示例1

[        Relative layout (match_parent)                ]
[child aligned right]

示例2

[Rel. Layout (wrap_content)]
[child has nowhere to align]

您可以将宽度设置为0dp,并将权重设置为1,从而使相对布局填充其父布局。

示例3

[                    Some layout parent                      ]
[ some other view ][relative layout with width 0dp, weight 1 ]
[child aligned right]

您可以将其制作成包装内容,但可能没有您想要的效果,因此请制作RelativeLayoutmatch_parent

最新更新