N
N
Nikita2018-11-06 20:32:52
Java
Nikita, 2018-11-06 20:32:52

How to resize a ConstraintLayout while the application is running?

I need to remove (height = 0) the child ConstraintLayout under a certain condition, and then show it again (height = match_constraint). Tried this:
Remove:

val c = ConstraintSet()
                c.clone(constraintLayoutTable)
                c.constrainMaxHeight(R.id.constraintLayoutTableTitle, 0)
                c.constrainPercentHeight(R.id.constraintLayoutTableTitle, 0.0f)
                c.applyTo(constraintLayoutTable)

Return:
val c = ConstraintSet()
                c.clone(constraintLayoutTable)
                c.constrainHeight(R.id.constraintLayoutTableTitle, ConstraintSet.MATCH_CONSTRAINT)
                c.constrainMaxHeight(R.id.constraintLayoutTableTitle, 100)
                c.constrainPercentHeight(R.id.constraintLayoutTableTitle, 100.0f)
                c.applyTo(constraintLayoutTable)

The above methods don't work.
The layout of the constraintLayoutTableTitle element
<android.support.constraint.ConstraintLayout
        android:id="@+id/constraintLayoutTableTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/textView13"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginBottom="8dp"
            android:text="I"
            android:textSize="24sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="I" />

        <TextView
            android:id="@+id/textView14"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:text="Test"
            android:textSize="24sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/textView13"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2018-11-09
@sputnic

for ConstraintLayout 0dp and MATCH_CONSTRAINT it's the same. Why don't you do it through Visibility?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question