Barrier doesn't set to referenceIds in constraint layout?

后端 未结 4 1706
长发绾君心
长发绾君心 2021-01-21 19:26

hey last few days I am exploring about the constraint layout.the concept of barrier I can understand but when i implement I can\'t get the correct output.

I want to set

相关标签:
4条回答
  • 2021-01-21 19:36

    Try this: you have to give both edittext start constraint to barrier.

    Also when I see in My android studio xml my output is same as you post in your question image. check http://prntscr.com/mkdtgb

    But when I see in device it's working

     <android.support.constraint.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:id="@+id/activity_main_barriers"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="8dp"
            android:text="barriers"
            android:textColor="@android:color/black"
            android:textSize="25sp"
            android:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
        <ImageView
            android:id="@+id/header"
            android:layout_width="0dp"
            android:layout_height="149dp"
            android:layout_marginTop="8dp"
            android:scaleType="centerCrop"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView" />
    
        <TextView
            android:id="@+id/title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="15dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:text="Arun Pandian"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="24sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/header" />
        <!--@string/hobbies-->
        <TextView
            android:id="@+id/passionLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:labelFor="@+id/etPassion"
            android:text="passios"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="15sp"
            app:layout_constraintBaseline_toBaselineOf="@+id/etPassion"
            app:layout_constraintStart_toStartOf="@+id/nameLabel" />
    
        <EditText
            android:id="@+id/etPassion"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:ems="10"
            android:inputType="textPersonName"
            android:layout_marginStart="16dp"
            android:text="Developing softwares"
            app:layout_constraintEnd_toEndOf="@+id/etName"
            app:layout_constraintStart_toEndOf="@+id/barrier2"
            app:layout_constraintTop_toBottomOf="@+id/etName" />
    
        <TextView
            android:id="@+id/nameLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:labelFor="@+id/cameraType"
            android:text="namegfhfgdfgdfgdfgdfgdfgdf"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="15sp"
            app:layout_constraintBaseline_toBaselineOf="@+id/etName"
            app:layout_constraintStart_toStartOf="parent" />
    
        <EditText
            android:id="@+id/etName"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:inputType="textPersonName"
            android:text="Arun Pandian"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/barrier2"
            app:layout_constraintTop_toBottomOf="@+id/title" />
    
    
        <android.support.constraint.Barrier
            android:id="@+id/barrier2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:barrierDirection="end"
            app:constraint_referenced_ids="nameLabel,passionLabel" />
        
    </android.support.constraint.ConstraintLayout>
    
    0 讨论(0)
  • 2021-01-21 19:45

    I resolved this issue by updating the ConstraintLayout library

    From

    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'

    To this

    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha3'

    0 讨论(0)
  • 2021-01-21 19:48

    This seems to be a rendering bug in the Preview in Android Studio 3.3. The barrier will works at runtime on the emulator.

    0 讨论(0)
  • 2021-01-21 19:54

    I had a similar issue when using

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    

    The same code was working in one project but not in another, both using the same version of the constraint-layout

    If it works on device and but not in the layout editor, then try to force refresh the layout in the editor

    0 讨论(0)
提交回复
热议问题