Animation 设置布局高度动画会产生奇怪的闪烁
我正在尝试为工具栏下和AppbarLayout内的布局(高度)设置动画。我尝试了几种方法:其中之一是使用ValueAnimator.ofInt并使用此int设置布局的高度。然而,这有点起伏。根据我读过的一些帖子,这是因为每次迭代都会调用requestLayout(),这是一个昂贵的操作。我看到的几乎所有其他选项都需要调用requestLayout()。在这种情况下,有些陈旧的设备将无法正常工作 另一种显然是最有效的方法是在父布局(本例中为AppbarLayout)中简单地声明animateLayoutChanges=true,并在代码中简单地更改高度。这确实有效,但它会产生奇怪的跳跃,好像布局立即非常迅速地到达其最终高度,再次折叠,然后开始正常动画。崩溃时也会发生同样的情况 在活动中,我只是调用setVisibility(View.VISIBLE)来展开,调用newTaskLayout.setVisibility(View.GONE)来折叠。我还尝试将“高度”设置为0,然后使视图塌陷,将“高度”设置为“包裹内容”,然后使视图可见以展开,但结果是一样的 这有什么原因和避免的方法吗?还是有更好的方法 这是XML:(正在设置动画的视图是工具栏下的COnstraintLayout)Animation 设置布局高度动画会产生奇怪的闪烁,animation,layout,Animation,Layout,我正在尝试为工具栏下和AppbarLayout内的布局(高度)设置动画。我尝试了几种方法:其中之一是使用ValueAnimator.ofInt并使用此int设置布局的高度。然而,这有点起伏。根据我读过的一些帖子,这是因为每次迭代都会调用requestLayout(),这是一个昂贵的操作。我看到的几乎所有其他选项都需要调用requestLayout()。在这种情况下,有些陈旧的设备将无法正常工作 另一种显然是最有效的方法是在父布局(本例中为AppbarLayout)中简单地声明animateLay
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="match_parent"
tools:context="com.adrapps.mytasks.Views.TaskListActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:title="App"
app:popupTheme="@style/AppTheme.PopupOverlay">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:paddingLeft="8dp"
android:paddingStart="8dp"
android:visibility="gone" />
</android.support.v7.widget.Toolbar>
<android.support.constraint.ConstraintLayout
android:id="@+id/new_task_layout"
android:layout_width="match_parent"
android:layout_height="164dp"
android:paddingBottom="16dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:visibility="visible">
<ImageView
android:id="@+id/title_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="0dp"
android:src="@drawable/ic_label"
app:layout_constraintBottom_toBottomOf="@+id/title_edit_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/title_edit_text"
tools:layout_editor_absoluteX="16dp" />
<ImageView
android:id="@+id/date_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_date"
app:layout_constraintBottom_toBottomOf="@+id/date_edit_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/date_edit_text"
app:layout_constraintVertical_bias="0.333" />
<ImageView
android:id="@+id/notification_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="16dp"
android:layout_marginTop="28dp"
android:src="@drawable/ic_notifications_none_black_24dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/date_icon"
app:layout_constraintTop_toBottomOf="@+id/date_icon" />
<EditText
android:id="@+id/title_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:hint="@string/task_title_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintLeft_toRightOf="@+id/title_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@id/title_icon"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/date_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="12dp"
android:hint="@string/task_due_date"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/date_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@id/date_icon"
app:layout_constraintTop_toBottomOf="@+id/title_edit_text" />
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/notification_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="6dp"
android:entries="@array/notification_options"
app:layout_constraintBottom_toBottomOf="@+id/notification_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@+id/notification_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/notification_icon" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add_black_24dp" />
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>