0

Ich benutze letzte Version von ConstraintLayout, 1.1.0-Beta4 und ich habe Probleme mit Barrier, wenn es ConstraintLayout innerhalb ScrollView ist. Hier ist das Layout:Schlechtes Verhalten von Barrier in ConstraintLayout in ScrollView

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    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" 
    > 

    <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:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:context="rs.agilesolutions.anothertesttodelete.MainActivity" 
     > 

     <Button 
      android:id="@+id/button" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_marginTop="8dp" 
      android:text="Button" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent"/> 

     <TextView 
      android:id="@+id/txt1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:text="Lorem" 
      android:textSize="40sp" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@id/button" 
      /> 

     <TextView 
      android:id="@+id/txt2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="8dp" 
      android:layout_marginTop="8dp" 
      android:text="Ipsum" 
      app:layout_constraintEnd_toEndOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/button"/> 

     <android.support.constraint.Barrier 
      android:id="@+id/barrier" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:barrierDirection="bottom" 
      app:constraint_referenced_ids="txt1,txt2" 
      /> 

     <TextView 
      android:id="@+id/txtResult" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:text="UNDER BARRIER" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="@+id/barrier"/> 

     <EditText 
      android:id="@+id/editText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginTop="8dp" 
      android:background="#00FF00" 
      android:ems="10" 
      android:hint="Name" 
      android:inputType="textPersonName" 
      android:text="Name" 
      app:layout_constraintEnd_toEndOf="parent" 
      app:layout_constraintStart_toStartOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/txtResult" 
      /> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginTop="8dp" 
      android:background="#FF0000" 
      android:ems="10" 
      android:hint="password" 
      android:inputType="textPassword" 
      app:layout_constraintEnd_toEndOf="parent" 
      app:layout_constraintStart_toStartOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/editText" 
      /> 
    </android.support.constraint.ConstraintLayout> 
</ScrollView> 

Barriere Richtung bottom von zwei Ansichten gesetzt (txt1 und txt2). Es sollte wie folgt aussehen:

The way it should look like

, sondern es sieht wie folgt aus:

The way it looks like

Zuerst in meiner echte app, ich habe eine Menge von Ansichten und dass ist der Grund ScrollView wird benötigt.

Zweitens indem Sie die Taste I zu ändern, aus Darstellungsgründen, die Sichtbarkeit von txt (die mit dem Lorem Text) drücken und damit zu testen, ob niedrigere Ansichten richtig verhalten werden.

Drittens, als Ergebnis ConstraintLayout berücksichtigt nicht, dass unter diesen Ansichten, für die Barriere verwiesen wird, kann es genug, um anderen Inhalt zu verbreiten, aber stattdessen füllt es nur bereits Platz für das Layout mit den restlichen Ansichten von unten.

Ist das ein Fehler in der Implementierung von ConstraintLayout?

Habe ich eine andere Wahl ohne die, in der ich im Code die Einschränkungen für diese Art von Situation ändere, und unabhängig von der Sichtbarkeit der Ansicht, setze ich dementsprechend die Position der verbleibenden Ansichten?

+1

Für mich sieht das richtig aus. Scheint ein Bug in der Beta4 zu sein. In der Beta3 sieht alles gut aus. Beachten Sie, dass 'wrap_content' im Layout selbst problematisch sein kann. Es kann nur funktionieren, wenn es keine expandierende Ansicht gibt (der obige Beispielcode sollte also funktionieren). –

Antwort

1

Wie Wolfram Rittmeyer sagte, ist dies wahrscheinlich Bug in dieser Version. Ich habe die Version auf Beta3 heruntergesetzt und alles funktioniert wie erwartet.

Verwandte Themen