Reputation: 4022
Is there any way to define childHeight as more important than its siblings and propagate its size to (less important) siblings.
Consider this layout
<RelativeLayout
match_parent,match_parent>
<FrameLayout
match_parent,match_parent>
<ViewA
this view size is important and its siblings should have same size, set on Runtime.
layout_gravity="center"/>
<ViewB
match_parent,match_parent
layout_gravity="center"
(should have the size of ViewB) />
</FrameLayout>
</RelativeLayout>
I know how to do it using ConstrainLayout but I am asking just out of curiosity
<ConstraintLayout>
<ViewA
wrap_content,wrap_content
constraint_to="parent"/>
<ViewB
0dp,0dp
constraint_to="ViewA"
layout_gravity="center"
(should have the size of ViewA) />
</ConstraintLayout>
Use case I have cameraView (ViewA) and cameraOverlay (ViewB). ViewA changes it's size according to user preference (16:9 | 4:3...) and ViewB (has some alpha) must always overlap whole ViewA.
Edit: Forgot to add that I don't want to change size of viewB manually
Upvotes: 3
Views: 148
Reputation: 266
I understand that you change the height/width of viewA programmatically. So you have the height and width resources available.
To others who have the same problem, to set the height of the View:
viewB.getLayoutParams().height = heightViewA;
viewB.getLayoutParams().width = widthViewB;
Hope this helps.
Important. If you're setting the height after the layout has already been 'laid out', make sure you also call:
viewB.requestLayout()
Another option is to use
RelativeLayout
<RelativeLayout
wrap_content,wrap_content
>
<ViewA
wrap_content,wrap_content
constraint_to="parent"/>
<ViewB
match_parent,match_parent
constraint_to="ViewA"
layout_gravity="center"
(should have the size of ViewA) />
</RelativeLayout>
And in RelativeLayout
you can overlay them.
Upvotes: 1