How can I use a RelativeLayout or LinearLayout inside in ConstraintLayout - android-constraintlayout

I am unable to add the inner layout (Relative layout or liner layout) inside the constraint layout. What do I have to do if I do

Related

Image view crush stackview constraints in swift?

I have some issue about my stackview contraints or imageview constraints ı dont know actually.Probably both . This is my stackview constraints stackViewConst and this my imageview constraints imaviewConstraints . When ı try to run ı expect everything looks awesome however unfortunately ı get this screen screen my stackview is lost.How ı can figure out this help me
Answer: add stackview height constraint
(or add stack view content resistence and content hugging priorities higher than those of your UIImageView)
Explanation:
Since you are using storyboard's Interface builder (IB) for creating constraints, as opposed to pure code. The IB uses feature of auto-constraints, which basically means that the IB can figure itself the layout and constraints based on what is displayed in your storyboard. The UIStackView is using some dynamic resizing (so that elements within stackview are properly layed out) and it is always good idea to give it size constraints, or at least size constraints to elements inside UIStackView , otherwise it might decide that every element has size of CGSize(height:0,width:0) You can also make priorities of your UIStackView higher than those of your UIImageView so that IB would prioritize the size of your stackview's constraints to those of your imageView

How to add custom UIView to Stackview on top of UIScrollView programmatically?

I have a ViewController that has a UIScrollView with a vertical UIStackView on top of it.
Everything works fine if i add UIView to the stackview with height constraint trough the interface builder. For example 3 views with height 600px. If i run the app, i can scroll with no problem and see all three added views. The for the stackview works fine.
If i try to add a view to the stackview with code with addArrangedSubView trough code i can see that the first view that i added if i "force" scroll down, but not the other two. It doesnt matter if i set height constraints to the views that i add, and it doesnt matter if i set intrinsicContentSize for the custom views.
How can i get the scroll view to expand the scroll area when adding trough code. ?
Thanks :)
Just a guess in lack of more information:
The issue may be related to the way constraints are set up between the scroll view and its child, the stack view.
you should add the following constraints:
fix stack view edges (top, leading, trailing, bottom) to scroll view
set width constraint between stack view and scroll view
also set height constraint between stack view and scroll view, set its priority to low (250)
For more insights please read up on "setup UIStackView with auto layout", for example here:
https://medium.com/#pradeep_chauhan/how-to-configure-a-uiscrollview-with-auto-layout-in-interface-builder-218dcb4022d7
If it doesn't work please provide the relevant code and screenshots of your Interface Builder setup.

UIStackView inside UITableViewCell: constraints not enabled

I have a horizontal UIStackView inside a UITableViewCell. Why can't I add constraints related to cell's content view in Storyboard?
If stackview ' layout is selected Translates Mask Into Constraints on Size Inspector' View page
You can't add constraints.
Change it with Automatic

How to make this scroll view scrollable?

I'm trying to add a horizontal scroll view to my view controller, but when I run the app I can't scroll. Here's an image:
How should I solve it?
The important thing here is how the constraints of the scroll view and its inner views are set.
You should first set constraint of the scroll view as you would do with another view, once this is done correctly it should have an x and y positions and also would be capable of know width and height.
After that you should set the constraints for inner views, making them push the boundaries of the container (the scroll view). So imagine you have 3 inner views you want to be set vertically:
The first one should have a top constraint to its container (scroll view), and a bottom to the second inner view.
The second one should have a bottom constraint to the third one.
The third one should have a bottom constraint to its container (scroll view).
This should satisfy all the calculation needs by AutoLayout.

How can implement stack view?

I'm using UIStackView in my Storyboard, but I can't understand how I can set constrains in UIStackview. How to implement Stackview in Storyboard using Autolayout in Swift?
The question is really generic. Can you be more specific, what kind of layout your are trying to achieve with the StackView.
Anyhow let me try to answer:
how can set constrains in stack view ?
StackView is a container/layout, generally used to arrange other UIViews.
You only need to constraint the StackView to the container view, the child views that are added to the stack are managed based on Axis, Distribution, Spacing, etc.
Axis: Vertical or Horizontal orientation of child elements added to the stack.
Alignment: Aligns the child element parallel to the Axis.
Distribution: Aligns the child element perpendicular to the Axis.
Spacing: Inter element spacing.
How to implement stack view in storyboard using auto layout in swift ?
You can set all the parameters/values mentioned above in the storyboard from Attribute Inspector.
For auto layout enable the following option in your storyboard by selecting the specific controller.
For adding proper constraints that resizes, avoid using constants and concentrate more on relative constraints.
Properly explained in OFFICIAL DOCUMENT