Questions tagged [android-constraintlayout]

A new type of layout available in the Android Support repository built on top of a flexible constraint system, marking views positions relative to each other.

ConstraintLayout is new type of layout that you can use in your android app. It is new powerful and flexible Android layout that allows you to express complex UI without nesting multiple layouts.

It is available since Android Studio 2.2, part of the support library and compatible from API level 9 (Android 2.3 GINGERBREAD).

ConstraintLayout aims at improving performance of layouts by reducing layout hierarchies and reduce the complexity of trying to work with RelativeLayout.

ConstraintLayout is compatible with other layout types such as RecyclerView, LinearLayout.

There are currently various types of constraints that you can use:

Relative positioning Margins Centering positioning Circular positioning Visibility behavior Dimension constraints Chains Virtual Helpers objects Optimizer

For more information about ConstraintLayout - Build a Responsive UI with ConstraintLayout

2760 questions
245
votes
10 answers

Differences between ConstraintLayout and RelativeLayout

I am confused about the difference between ConstraintLayout and RelativeLayout. Could someone please tell me the exact differences between them?
239
votes
14 answers

How to make ConstraintLayout work with percentage values?

With a Preview 1 of Android Studio 2.2 Google released a new layout in its support library: ConstraintLayout. With ConstraintLayout it is easier to use a Design tool in Android Studio, but I didn't find a way to use relative sizes (percents or…
Yury Fedorov
  • 12,277
  • 6
  • 44
  • 63
238
votes
8 answers

How to center the elements in ConstraintLayout

I am using ConstraintLayout in my application to make applications layout. I am trying to a create a screen wheren one EditText and Button should be in center and Button should be below of EditText with a marginTop only 16dp. Here is my layout and…
N Sharma
  • 28,073
  • 81
  • 228
  • 405
196
votes
5 answers

Evenly spacing views using ConstraintLayout

A common use for LinearLayout is to evenly space (weight) views, for example: How do you implement evenly spaced views like this using the new ConstraintLayout? ConstraintLayout links for reference: blog post, I/O session video
AdamK
  • 19,771
  • 5
  • 37
  • 54
170
votes
17 answers

Android - how to make a scrollable constraintlayout?

I want to make a layout that lets me scroll down using constraint layout, but I don't know how to go about it. Should the ScrollView be the parent of the ConstraintLayout like this?
154
votes
7 answers

Wrap_content view inside a ConstraintLayout stretches outside the screen

I am trying to implement a simple chat bubble using a ConstraintLayout. This is what I am trying to achieve: However, wrap_content does not do what I want. It respects the margins, but expands outside of the view bounds. Here is my layout:
Marcin Jedynak
  • 3,079
  • 2
  • 16
  • 19
153
votes
7 answers

ConstraintLayout: change constraints programmatically

I need help with ConstraintSet. My goal is to change view's constraints in code, but I cant figure out how to do this right. I have 4 TextViews and one ImageView. I need to set ImageView constraints to one of the TextViews. check_answer4 =…
144
votes
12 answers

How to achieve overlap/negative margin on Constraint Layout?

Is it possible to achieve negative margin on constraint layout to achieve overlap? I am trying to have a image centered on the layout and have a Text view such that it overlaps a by x dp. I tried setting negative margin value but no luck. It would…
bond
  • 10,356
  • 6
  • 44
  • 60
140
votes
22 answers

Gradle Sync failed could not find constraint-layout:1.0.0-alpha2

Problem : Error:Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha2. Required by: myapp:app:unspecified Background : Android Studio 2.2 P 1
Cool
  • 10,038
  • 13
  • 56
  • 77
132
votes
12 answers

Is it possible to put a ConstraintLayout inside a ScrollView?

So recently, with Android Studio 2.2 there's a new ConstraintLayout that makes designing a lot easier, but unlike RelativeLayout and Linearlayout, I can't use a ScrollView to surround ConstraintLayout. Is this possible? If so, how? i.e.
126
votes
9 answers

Android ConstraintLayout - Put one view on top of another view

I'm trying to add a ProgressBar on top of a Button (both are inside a ConstraintLayout).
124
votes
2 answers

What is difference between Barrier and Guideline in Constraint Layout?

Recently trying to implement Constraint Layout but I found Barrier and Guideline works same. Both works like divider. Is there any difference between them?
Yeahia2508
  • 5,836
  • 10
  • 38
  • 63
111
votes
11 answers

Set width to match constraints in ConstraintLayout

I would like to constrain a View's left and right sides to it's parent view's margins and make it fill the allotted space. However, setting width to either match_parent or wrap_content appears to produce the same result. Is there something…
KG6ZVP
  • 3,319
  • 4
  • 23
  • 43
105
votes
7 answers

Constraint Layout Vertical Align Center

How to vertically align and center objects in constraint layout? It is possible to align vertically or horizontally but I have not found a way to center at the same time beside constraining the views between two gridlines. Vertical Align…
Ray Li
  • 5,637
  • 5
  • 19
  • 33
89
votes
3 answers

ConstraintLayout aspect ratio

Consider the following layout file:
1
2 3
99 100