Issue
I'm trying to set the height of an element to be longer on 18:9 screens and its working funny. This line of code
includeExteriorFrame.setLayoutParams(new ConstraintLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen._420sdp)));
is giving me some trouble. I'll unpack it point by point:
1 - The function setLayoutParams threw an exception at first because I was using FrameLayout.LayoutParams instead of ConstraintLayout.LayoutParams. I remark this because on the declaration of includeExteriorFrame I'm declaring it to be a FrameLayout, but as you can see, the LayoutParams are declared as ConstraintLayout. Why does this work? Is it because the FrameLayout is inside a ConstraintLayout?
2.- When I resize the elements they stick to the top of the screen. This I suppose has to do with how the resize updates the element. I've tried setting the element constraints afterwards, but to no avail, they are really stuck to the top.
I've tested many solutions to this problem, like setting both dimensions using pure int variables, setting other components aswell as the one I'm trying to resize and I've looked for a better function that won't get the element stuck, but I couldn't find anything, so I've decided to ask this. More info can be provided if needed.
Thank you so much for your attention.
Solution
I found the solution thanks to the first comment on the post. The solution was applying the constraints I was setting like so:
ConstraintSet constraintSet = new ConstraintSet();
ConstraintLayout constraintLayout = (ConstraintLayout) includeExteriorFrame.getParent();
constraintSet.clone(constraintLayout);
constraintSet.connect(includeExteriorFrame.getId(),ConstraintSet.BOTTOM,includeFrame.getId(),ConstraintSet.TOP);
constraintSet.connect(includeExteriorFrame.getId(),ConstraintSet.TOP,includeExteriorFrameParent.getId(),ConstraintSet.TOP);
constraintSet.applyTo(constraintLayout);
Answered By - Pedro Montesinos Navarro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.