last day (15 days later) » 

6:29 PM
0
Q: Android: How to use constraint_height_percent inside a layout that will be included in a parent layout

AndrewCurrently, I am trying to make my heights and widths of my views relative to the available space, so my ui will be more responsible. The problem I encounter is that whenever I try to include this layouts inside a parent layout (e.g include shop_content inside fragment_shop), the heights and width...

 
Something got in my mind after posting an answer .. you need 17% of the given height to the Toolbar .. I assume you need this from the total height of the parent layout (not the height of the child layout), there are two options you need to do this: first the Toolbar must be a child of the parent layout ConstraintLayout to constraint the 17% from it. second: your child layout shouldn't have any constraints to the Views in the parent layout.. in order to fill the entire area of its parent, and therefore to allow the toolbar height to be 17% of the entire height..
 
toolbar CANT BE a child of the parent constraintlayout, because this would make the include tag obsolete. If toolbar must be child of the parent layout, then how am I able to include it? Could you maybe change your answer then, applying yours doesn't fix mine. Second, the toolbar should NOT fill the entire parent, but only 0.17 of it. What is the pupose of my toolbar that fills the entire view, when the recyclerview is not shown anymore?
 
sure I will .. but need to understand more .. Now you need the toolbar to be 17% of the parent layout .. Do you want the child layout to have the same height/width of the parent?
 
@Zain I've edited my question, hope it is understandable with this.
 
Thanks for editing the question .. In your phrase ` in which the layout is included in` do you mean the app_standard_checkout_btn or the layout that reference it ?
 
6:29 PM
The layout that references it. So if fragment_shop includes app_standard_checkout_btn, toolbar height should be 0.15 of fragment_shop height
 
Cool .. now you want the Toolbar to be 17% of the parent layout while it's not a direct child of it.. that looks strange .. as the Toolbar is not a direct child of the parents ConstraintLayout, so you can't constraint it to the parent ConstraintLayout; but what you can do is to constraint the entire child layout to the parent layout.. And that is what I did in the answer .. to limit the size of the entire child layout by limiting its height to certain constraints .. or hard-coding
 
6:47 PM
So, what you need to do is to put height constraint to the child layout (that is apparently shown on your picture as it has 0 height)...
One option that looks better to me than of the answer, as the RecyclerView can be long so that the child height can be small.. The option is to constraint the child layout to the parent not to the RecyclerView .. I will update the answer with this shortly
 
Okay, I am looking forward for the new answer.
 
7:08 PM
@Andrew you can check it now
 
7:18 PM
Should the layout height of the child_layouts constraintlayout be "wrap_content"?
 
7:36 PM
It should be match constraint I believe .. but in this case I think it doesnt matter as you already matching the constraint while including it
in <include>
I modified that in answer though
 
Yes, I've applied your answer, but I think it won't fit my case here. Adding "constraint_height" to the included layout takes too much available space I need. In this case, there would just be white space between recyclerview and btn. But I appreciate your answer, thank you very much for trying to help me.
Maybe if you have later time, I could show you my problem in a max 10 min zoom session, but you don't need no if you don't want too
to*
 

last day (15 days later) »