2

I only started studying android development recently. Right now, I'm focusing on ConstraintLayout.

I've been using this codelab to learn. https://codelabs.developers.google.com/codelabs/constraint-layout/index.html?index=..%2F..%2Findex#10

I'm currently stuck at the barriers part of the codelab. When I try to constraint other views against the barrier, it doesn't seem to interact with the barrier at all.

In the codelab, readers are told to "drag a constraint from the left side of cameraType to the barrier," but when I do that, nothing happens.

I've tried googling how to use barriers for constraints, but I haven't been able to find any information other than what I've already seen in the codelab. Has there been a change on how you do this? Or is there something I have to change with Android Studio?

Is anyone else experiencing this?

Edit: For clarity's sake, here's a link to a gif(from the codelab) which is precisely what I'm trying, but failing, to do.

https://codelabs.developers.google.com/codelabs/constraint-layout/img/ca458bff73338979.gif

Draugen
  • 21
  • 3

2 Answers2

0

Cross check if you have set that EditText Box's android:layout_width="0dp" and drag that constraint to barrier because it will not expand otherwise.

Did you followed this step?

Important: Barriers start with their barrierDirection set to left. Make sure you update your barrierDirection to right or end.

if not then set your barrierDirection to end which is by default set to left, the problem may also lie there

gagangamer
  • 14
  • 1
  • 6
  • Thank you for your response. What element should I specifically make sure to have a layout_width of 0dp? After reading your comment, I tried changing most layout_widths to 0dp but nothing happened. And could you please clarify what are you referring to when you said "it will not expand"? Thank you. For clarity's sake, here is a link to a gif(from the codelab) which is precisely what I'm trying, but failing, to do. https://codelabs.developers.google.com/codelabs/constraint-layout/img/ca458bff73338979.gif – Draugen May 05 '20 at 07:41
  • Yes, I followed that step where you change the direction of the barrier. Yes, I made sure that the EditText box's layout_width was match constraint/0dp. I was able to create a constraint using the EditText's anchor but could only attach it to anchors of other views and the parent's sides(left, top, bottom, right.) I don't know why, but it seems to be ignoring the barrier. Am I doing anything wrong? Or maybe there were changes that came with a certain update that changed the way developers can do this? – Draugen May 07 '20 at 03:04
  • I've also tried starting from scratch(empty activity) rather than using the project provided as part of the codelab. I still couldn't constraint any view to any barrier(except for the views referenced via the component tree.) – Draugen May 07 '20 at 03:11
  • By the way, thanks for replying and for trying to help. I guess I'll learn how to work around it in the future. Like, wrapping both textViews within a LinearLayout. That would get me similar results. But it would be nice if I can find a way to make barriers work. – Draugen May 07 '20 at 03:18
  • Did you read that line ?? - "You won't find the barrier in Design or Blueprint view yet because it's flush with the start of the container." That's where your problem exists. I tried it myself and figured out. Now, what you have to do is don't follow the step no. 5 exactly. Just drag and drop camera Label and Settings label one by one. and then follow this step - "Drag a constraint from the left side of cameraType to the barrier" – gagangamer May 08 '20 at 07:24
  • if you are unable to do this on design view then switch to split view and find EditText with camera type there and add this line :- app:layout_constraintStart_toEndOf="@+id/barrier" . It is similar to draging constraint. – gagangamer May 08 '20 at 07:24
  • Yes, I read that line. I referenced the two TextViews(cameralabel and settingslabel) using the component tree. So yes, I followed step no.5 exactly. So no, this isn't where my problem exists. – Draugen May 09 '20 at 03:35
  • Okay, manually inputting the code works. I wasn't able to properly check if it worked the last time I tried manually inputting code. Back then, I tried to check by moving the EditTexts after constraining them relative to the barrier and I thought it wasn't constrained properly because the layout editor automatically increased the value for margins. That gave me the illusion that it wasn't working as intended. I still can't make it work via design view though. At least now I know manually inputting code works if I really need to use barriers. Thanks – Draugen May 09 '20 at 04:25
  • Yes, sometimes there are some bugs that can ruin our days. – gagangamer May 09 '20 at 07:01
0

I have the same issue with Design mode. But in Text mode if we add something like app:layout_constraintStart_toEndOf="@id/barrier" the views constraint properly.

Sergey V.
  • 981
  • 2
  • 12
  • 24
  • Thank you for responding. It's good to see that I'm not alone in this. I thought it was an issue with my hardware or something. I hope they fix this in future versions of Android Studio. At least manually inputting code works. Thank you. – Draugen Jun 06 '20 at 04:53