4

I'm having a strange problem: layout.xml

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="wwwwwwwwwwwwwwwwwww" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="wedwdwqefwerfwe"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="51dp" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="end"
        app:constraint_referenced_ids="textView5,textView4"
        tools:layout_editor_absoluteX="411dp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="275dp"
        tools:layout_editor_absoluteY="155dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

I'm trying to connect a widget to my barrier. The problem is that when I try to connect the END of my widget with the barrier, there is no connection (I can't do that, I drag and drop without success). Here's an image of me trying to connect, but it is not possible. enter image description here

l000000l
  • 330
  • 1
  • 3
  • 14
  • 1
    Add the constraint manually in the XML editor. – Francesc May 18 '20 at 01:17
  • Tried adding `app:layout_constraintStart_toEndOf="@+id/barrier"`, no errors but not working. – l000000l May 18 '20 at 01:19
  • 1
    A barrier does not make sense with a single referenced ID, a barrier should reference at least 2 widgets. Do you need a barrier in this scenario? – Francesc May 18 '20 at 01:28
  • I tried also adding 2 widgets but the problem is the same. However, I only need to create a vertical "margin" referenced to an ID and set the `end` of my widgets to that margin. – l000000l May 18 '20 at 10:05
  • Could I use something else to achive this? I tried with a `guideline`, but I don't want to have a fixed size guideline (`app:layout_constraintGuide_begin="327dp"`) but I want to be relative to the position of the `END` of a widget.. – l000000l May 18 '20 at 10:10
  • I updated my question with a clear example of what is happening. Let me know if you have any ideas. Thanks! – l000000l May 18 '20 at 10:21

1 Answers1

1

your quetion is still unclear but as I understand you are not able to connect view with barrier right?

enter image description here

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="wwwwwwwwwwwwsdfdsfw"
        android:textSize="@dimen/_15ssp"
        app:layout_constraintEnd_toStartOf="@+id/barrier"
        app:layout_constraintStart_toStartOf="parent" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/_20sdp"
        android:text="wedwdwqefwerfwe"
        android:textSize="@dimen/_15ssp"
        app:layout_constraintEnd_toStartOf="@+id/barrier"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView4" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="end"
        app:constraint_referenced_ids="textView5,textView4"
        tools:layout_editor_absoluteX="411dp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/barrier"
        tools:layout_editor_absoluteX="275dp"
        tools:layout_editor_absoluteY="155dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57