How to set `LinearProgressIndicator`'s height in a `MotionLayout` scene?

39 Views Asked by At

I use a LinearProgressIndicator inside a MotionLayout that I would like its height to vary from default value to 0. Setting layout_height doesn't change the progress bar's height at all. According to this question, trackThickness is the way to go. But setting this value in the scene doesn't change the LinearProgressIndicator's height.

Here is what I tried:

<?xml version="1.0" encoding="utf-8"?>
<MotionScene
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:motion="http://schemas.android.com/apk/res-auto">

  <ConstraintSet android:id="@+id/start">
    <Constraint android:id="@id/now_playing_progress">
      <CustomAttribute
        motion:attributeName="trackThickness"
        motion:customDimension="?attr/trackThickness"
      />
    </Constraint>
  </ConstraintSet>

  <ConstraintSet android:id="@+id/end">
    <Constraint android:id="@id/now_playing_progress">
      <CustomAttribute
        motion:attributeName="trackThickness"
        motion:customDimension="0dp"
      />
    </Constraint>
  </ConstraintSet>

  <Transition
    motion:constraintSetEnd="@id/end"
    motion:constraintSetStart="@+id/start"
  >
    
  </Transition>
</MotionScene>

Edit: the code I tried from C.F.G's solution:

<!-- Layout -->

<?xml version="1.0" encoding="utf-8"?>
<layout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">

  <merge>
    <!-- Placeholder for setting constraints and interacting -->
    <View
      android:id="@+id/constraint_layout_placeholder"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      app:layout_constraintTop_toTopOf="parent"
    />

    <com.google.android.material.progressindicator.LinearProgressIndicator
      android:id="@+id/now_playing_progress"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:layout_constraintTop_toTopOf="@id/constraint_layout_placeholder"
      android:progress="@{progress, default=40}"
      android:progressTint="@color/colorPrimaryDark"
    />

    <!-- Snip -->
  </merge>
</layout>

<!-- Scene -->
<?xml version="1.0" encoding="utf-8"?>
<MotionScene
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:motion="http://schemas.android.com/apk/res-auto">

  <ConstraintSet android:id="@+id/start">
    <Constraint android:id="@id/constraint_layout_placeholder">
      <PropertySet android:visibility="visible" />
    </Constraint>
  </ConstraintSet>

  <ConstraintSet android:id="@+id/end">
    <Constraint
      android:id="@id/now_playing_progress"
      android:layout_height="0dp"
      motion:layout_constraintBottom_toBottomOf="parent"
      motion:layout_constraintHeight_percent="0"
      motion:layout_constraintTop_toTopOf="parent" />
    <Constraint android:id="@id/constraint_layout_placeholder">
      <PropertySet android:visibility="invisible" />
    </Constraint>
  </ConstraintSet>

  <Transition
    motion:constraintSetEnd="@id/end"
    motion:constraintSetStart="@+id/start"
    >
  </Transition>
</MotionScene>

0

There are 0 best solutions below