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
43
votes
6 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…
42
votes
15 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…
41
votes
9 answers

Android percent screen width in RecyclerView item

How would I get a RecyclerView's item height to be, say, 30% of the screen's height? I can't simply use a ConstraintLayout or a PercentFrameLayout/PercentRelativeLayout, since those position child layouts relative to parent layouts, whose size might…
davidchuyaya
  • 3,192
  • 2
  • 13
  • 23
41
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…
41
votes
2 answers

No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package

I am using the Android SDK 2.2.3. I am following a book on programming Android. The code is:
39
votes
6 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
  • 2,249
  • 3
  • 23
  • 40
39
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,746
  • 2
  • 19
  • 30
39
votes
5 answers

ConstraintLayout: how to have a view be half the screen width and centered?

TL;DR The view width must be exactly half of the screen, and be centered. Using ConstraintLayout. Note that the view does not have any inner width. Original question I would like to achieve a layout where a…
Softlion
  • 11,311
  • 10
  • 52
  • 78
38
votes
2 answers

How to set a maximum width for a view in an android constraintLayout?

I have a layout that looks like this:
pjc
  • 735
  • 1
  • 6
  • 12
37
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____
  • 592
  • 1
  • 5
  • 6
37
votes
14 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…
36
votes
2 answers

Is it advisable to use LinearLayout inside ConstraintLayout in Android?

I am new to ConstraintLayout in Android and newbie to Android too. I have a question. Is it advisable to use LinearLayout inside ConstraintLayout? For example:
TechBee
  • 1,809
  • 3
  • 22
  • 45
33
votes
1 answer

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
  • 7,338
  • 3
  • 28
  • 41
33
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
  • 17,607
  • 16
  • 70
  • 175
33
votes
2 answers

How to group multiple views in a ConstraintLayout

I have added 3 buttons in a ConstraintLayout. I have added a button to disable or enable these buttons. If I was using normal LinearLayout. I could have put all the buttons in a Linear Layout and enable or disable that particular layout. But I am…