4

I have a XML layout for a ViewHolder inside a RecyclerView.

This layout's root is a ConstraintLayout whose height is set to wrap_content.

Inside this flat hierarchy there are 3 textviews and an image view with a fixed height; think of:

<ConstraintLayout>
     <TextView height=wrap>
     <TextView height=wrap>
     <TextView height=wrap>
     <ImageView height=150dp>
</ConstraintLayout>

It's a relatively simple layout. In beta4 this is how it looks in the Designer (and eventually at runtime, each recyclerView cell):

Beta4

Apologies for the "red tape" but it's NDA blah blah.

That being said, the elements are:

The 3 text views (red taped with a nice purple background) The ImageView with 150dp height is the gray thing.

The Purple background was applied to the root ConstraintLayout. All nice.

Now this is how it looks, without a single modification with Beta 5:

beta5

As you can see the Purple (root) Constraint Layout is now "confused" and doesn't wrap content as it used to.

Things I tried:

  1. Adding app:layout_constraintHeight_default="wrap" to the ConstraintLayout (and spread too). Didn't make a difference.

  2. The ImageView has a app:layout_constraintBottom_toBottomOf="parent" constraint that I tried removing, didn't make a difference either.

  3. Revert back to beta4 :)

For the record, this is the full layout (id's have been renamed for red-tape reasons and no tools:text or similar due to the same reasons). The layout is otherwise exactly the same.

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:background="@color/colorAccent">

    <TextView
        android:id="@+id/toplabel"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text=""
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="@+id/top_bottom_label"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/top_right_label"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/top_right_label"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        android:ellipsize="end"
        android:gravity="end"
        android:maxLines="1"
        android:text=""
        app:layout_constraintBottom_toTopOf="@+id/top_bottom_label"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toRightOf="@+id/toplabel"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="packed" />

    <TextView
        android:id="@+id/top_bottom_label"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        android:ellipsize="end"
        android:gravity="end"
        android:maxLines="1"
        android:text=""
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toRightOf="@+id/toplabel"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/top_right_label" />

    <ImageView
        android:id="@+id/imageview"
        android:layout_width="0dp"
        android:layout_height="150dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/top_bottom_label"
        app:srcCompat="@android:color/darker_gray" />

</android.support.constraint.ConstraintLayout>

Am I supposed to do something different? (I know I can replace this with a RelativeLayout and probably do the same, but anyway… I believe in ConstraintLayout!) :)

Eugene Brusov
  • 17,146
  • 6
  • 52
  • 68
Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144

1 Answers1

6

I filed a bug about this and I got a workaround.

It's a regression and will be fixed (we hope) but… turns out my Chain is also incorrectly defined. My top_bottom_label does not have a bottom endpoint, and according to the documentation elements in a chain should be connected on both endpoints.

So I added app:layout_constraintBottom_toTopOf="@id/imageview" to the top_bottom_label and this seems to work for my case. I have, effectively added the imageView to the chain, even do I don't really care much for it. It works for now.

Update February 14th 2017: The ConstraintLayout team @ Google fixed the issue in master. It will likely be fixed in a next release. (Thanks!).

Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144