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

3207 questions
52
votes
4 answers

Group views in ConstraintLayout to treat them as a single view

I need to apply some constraints to a group of views in ConstraintLayout. I want to group these views and continue editing while the layout designer in Android studio treats them as a single view. Is there a way to do so without actually wrapping…
51
votes
16 answers

Scrollview inside constraint layout does not scroll to the bottom of the parent constraint

I have a form which has around 12/13 fields. I used a Scrollview inside a constraint layout. Below is the hierarchy of the XML layout. The problem is, it doesn't scroll to the bottom instead scrolls only to the first initial 10 views. The last 3…
50
votes
8 answers

Use group in ConstraintLayout to listen for click events on multiple views

Basically I'd like to attach a single OnClickListener to multiple views inside a ConstraintLayout. Before migrating to the ConstraintLayout the views where inside one layout onto which I could add a listener. Now they are on the same layer with…
Endzeit
  • 4,810
  • 5
  • 29
  • 52
50
votes
4 answers

How can I get the latest version of ConstraintLayout for Android?

When I try to use ConstraintLayout in my layout content_main.xml, I get the following message: Using version 1.0.0-alpha5 of the constraint library, which is obsolete I am currently using the following library dependency: compile…
Nabeel K
  • 5,938
  • 11
  • 38
  • 68
49
votes
4 answers

ConstraintLayout max width percentage

I've been experimenting with ConstraintLayout, is there a way to set the max width of a view to a percentage of the parent (and a height of match constraint and dimension ratio of 1:1)? Here is the code without using max width:
49
votes
6 answers

Using with in ConstraintLayout

I am having trouble using tags and inside a ConstraintLayout. I want to create a flat view hierarchy (hence Constraints) but still have elements that are reusable. So I use in my layout and in the included…
JDenais
  • 2,956
  • 2
  • 21
  • 30
49
votes
4 answers

app:layout_marginBottom is not working well with android constraint layout

Is there any reason why the following layout_marginBottom is not working? However, if I use layout_marginTop on the second view it does work well
Ron____
  • 782
  • 1
  • 6
  • 6
49
votes
17 answers

How to switch from the default ConstraintLayout to RelativeLayout in Android Studio

I have the latest android Studio (2.3 beta 3) and it seems ConstraintLayout is the default when creating a project. How can I make Android Studio use the RelativeLayout as the default layout element for new projects ?
44
votes
5 answers

ConstraintLayout views in top left corner

Every time I create views like Button and TextView in ConstraintLayout, they all get stuck at the top corner instead of where I placed them. I tried to create new activities and change the emulator, but the result is still the same. This is a…
43
votes
5 answers

Can't set visibility on constraint group

When i try to set the visibility of the group on button click,it doesn't affect the view's visibility.Using com.android.support.constraint:constraint-layout:1.1.0-beta4. I've tried setting it element-wise without problems,but no success with the…
43
votes
4 answers

How to make view "wrap_content but not larger than" with ConstraintLayout?

I'm having 3 view in a row: title, version and imageview (working as button): title should be wrap_content but respecting the following rules version should be wrap_content, to right of the title and to left of imageview imageview has fixed size…
4ntoine
  • 19,816
  • 21
  • 96
  • 220
42
votes
2 answers

Chain with a barrier in ConstraintLayout

I want to achieve the layout below using a ConstraintLayout with no nesting. The layout requires a barrier since it's not guaranteed which textview will be taller. It also requires a chain since everything needs to be centered. The issue is that I…
idunnololz
  • 8,058
  • 5
  • 30
  • 46
42
votes
3 answers

How to make Constraint Layout Guideline in center

I have 3 Guideline in Constraint Layout. One is in left with 16dpleft margin. Second is in right with 16dp right margin. But I want another Guideline which will be in center. Suppose If I make this guideline center in nexus 5 from Android Stdio XML…
Yeahia2508
  • 7,526
  • 14
  • 42
  • 71
42
votes
2 answers
42
votes
16 answers

Can't form a chain between two views/widgets in Android Studio

When I'm using the layout editor in Android Studio and I try to make a chain (bidirectional constraint) between a EditText View and a Button View using the constraint anchors, it doesn't make the chain. It only makes a constraint if I try to…