This error occurs when you try to start animating a view that is not yet attached to the layout.
However, there seems to be a missing corner, in which in some cases in API 23 (Marshmellow), when you try to animate certain views with a set elevation level, the application closes no matter what.
Let's say your current code is:
<FrameLayout android:id="@+id/container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:elevation="@dimen/custom_elevation" />
container.animate() .scaleX(1f) .scaleY(1f) .setListener(null) .start();
In this case, you have several workarounds:
- Remove height from view
- Delete animation that contains height
- Remove height for API 23 only
- Remove animation for API 23 only
- Temporarily remove the mark and add the mark back after the animation is completed:
<FrameLayout android:id="@+id/container" android:layout_width="wrap_content" android:layout_height="wrap_content" />
container.animate() .scaleX(1f) .scaleY(1f) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); final float elevation = container.getDimension(R.dimen.custom_elevation); container.setElevation(elevation); } }) .start();
source share