在ConstraintLayout内填充RecyclerView后对视图进行动画处理

时间:2019-02-02 21:12:34

标签: android android-recyclerview android-animation

我正在以ConstraintLayout作为其根视图的布局。里面有一个RecyclerView和一个TextView按钮。单击该按钮后,视图将添加到RecyclerView中,并且该按钮会降低。但是该按钮未设置动画。如何根据将视图添加到RecyclerView的速度对按钮进行动画处理?

编辑

问题似乎更加严重,因为这是为所有视图设置正确尺寸(我的RecyclerView的高度设置为wrap_content)的问题,因此我将添加布局的缩减副本:< / p>

<androidx.constraintlayout.widget.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:id="@+id/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:background="@color/darkGrey"
    android:focusableInTouchMode="true">

  <include
      layout="@layout/layout_item_toolbar"
      android:id="@+id/toolbar"
      />

  <androidx.core.widget.NestedScrollView
      android:id="@+id/scrollView"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:animateLayoutChanges="true"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@id/toolbar"
      >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true"
        >

<EditText
          android:id="@+id/etDuration"
          android:layout_width="0dip"
          android:layout_height="wrap_content"
          android:background="@drawable/edit_text_background"
          android:elevation="1dp"
          android:hint="Duration"
          android:scrollHorizontally="false"
          app:layout_constraintBottom_toTopOf="@+id/tvEndDate"
          app:layout_constraintEnd_toStartOf="@+id/spDuration"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@id/chipGroup"
          />

      <Spinner
          android:id="@+id/spDuration"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          app:layout_constraintBottom_toBottomOf="@+id/etDuration"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@id/etDuration"
          app:layout_constraintTop_toTopOf="@id/etDuration"
          />


      <TextView
          android:id="@+id/tvEndDate"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:visibility="gone"
          app:layout_constraintBottom_toTopOf="@+id/tvAddTask"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@id/etDuration"
          />
      <androidx.constraintlayout.widget.Barrier
          android:id="@+id/barrier3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          app:barrierDirection="bottom"
          app:constraint_referenced_ids="etDuration,tvEndDate"
          />

      <TextView
          android:id="@+id/tvNumberOfTasks"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="15dp"
          android:layout_marginTop="10dp"
          app:layout_constraintBottom_toTopOf="@+id/rcvTasks"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@id/barrier3"
          />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rcvTasks"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            app:layout_constraintBottom_toTopOf="@+id/tvAddTask"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvNumberOfTasks"

            />
      <TextView
          android:id="@+id/tvAddTask"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@id/rcvTasks"
          />

    </androidx.constraintlayout.widget.ConstraintLayout>

  </androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

0 个答案:

没有答案