Yesudass Moses
Yesudass Moses

Reputation: 1859

ConstraintLayout not showing child views

I am hiding and showing a textview programmatically. Parent constraint layout has set the height 'wrap_content'.

But the issue here is If the textview is hidden initially, even if I set the textview visibility to VISIBLE, ConstraintLayout titleLayout keeps collapsed and not showing the child textview.

Setting the height of the ConstraintLayout to wrap_content is important so the layout can grow/shrink as per the textview content.

 <android.support.constraint.ConstraintLayout
            android:paddingTop="10dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

 <android.support.constraint.ConstraintLayout
            android:id="@+id/descriLayout"
            android:layout_width="match_parent"
            app:layout_constraintTop_toBottomOf="@id/titleLayout"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="5dp"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/box_description"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginRight="8dp"
                android:layout_marginStart="8dp"
                android:text="TextView"
                android:textSize="12sp"
                android:maxLines="5"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>
        </android.support.constraint.ConstraintLayout>
   </android.support.constraint.ConstraintLayout>

Upvotes: 2

Views: 1210

Answers (1)

Daniel Zolnai
Daniel Zolnai

Reputation: 16910

If you are changing the visibility of the childs inside a ConstraintLayout, you have to do it via a ConstraintSet:

ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.setVisibility(childView.getId(), View.VISIBLE);
constraintSet.applyTo(constraintLayout);

Upvotes: 1

Related Questions