Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 constrain one View to the other.

I am trying to chain the right side of the EditText to the left side of the Button.

This is what my Layout Editor looks like:

Layout Editor

like image 754
C.Kraz Avatar asked Mar 13 '17 06:03

C.Kraz


People also ask

How to create chains in Android Studio?

Chains in XMLOn textView there is app:layout_constraintEndToStartOf="@+id/textView2" ; and on textView2 there is app:layout_constraintStart_toEndOf="@+id/textView" - essentially creating two constraints between the same pair of anchor points in opposite directions. It is this which defines a chain.

How do you use chains in constraint layout?

Creating a chain is really easy, we can click and drag to select views or press ctrl and select views from Component Tree. And then right click on selected views in Editor Or Component Tree to apply constraints. You can see that in action in following screen records.


2 Answers

I was trying to figure this out too. I've discovered that one way to do it is to select both views, then right click and select Center Horizontally. This creates the chain, but then you have to adjust any other constraints accordingly. I'm new to Android, so I'm sure there will be other ways....

like image 132
Swud Avatar answered Oct 12 '22 09:10

Swud


I had the same issue. Solved it by going in into the XML as instructed by the tutorial: https://developer.android.com/training/basics/firstapp/building-ui.html

On the tutorial, click "See the final layout XML" and compare. My XML was missing:

app:layout_constraintLeft_toRightOf="@+id/editText" 
like image 45
Gustav Eriksson Avatar answered Oct 12 '22 09:10

Gustav Eriksson