Reputation: 1779
I found the following code that I use to flip two CardViews containing a chart (I use MPAndroidCharts lib), creating a 3D card flip effect:
public class FlipAnimation extends Animation {
...
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
// Angle around the y-axis of the rotation at the given time
// calculated both in radians and degrees.
final double radians = Math.PI * interpolatedTime;
float degrees = (float) (180.0 * radians / Math.PI);
// Once we reach the midpoint in the animation, we need to hide the
// source view and show the destination view. We also need to change
// the angle by 180 degrees so that the destination does not come in
// flipped around
if (interpolatedTime >= 0.5f) {
degrees -= 180.f;
fromView.setVisibility(View.GONE);
toView.setVisibility(View.VISIBLE);
}
if (forward)
degrees = -degrees; //determines direction of rotation when flip begins
final Matrix matrix = t.getMatrix();
camera.save();
if(horizontal){
camera.rotateX(degrees);
} else {
camera.rotateY(degrees);
}
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
The original code was only able to flip along the vertical center axis, so I added that little if
when a boolean is set, then the animation is made along the horizontal center axis. Now sometimes during the animation, the following weird error crashes my app:
03-20 16:37:26.369 551-579/c.f.q.android.demo A/OpenGLRenderer: Error: Spot pair overflow!!! used 30, total 22
03-20 16:37:26.370 551-579/c.f.q.android.demo A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 579 (hwuiTask1)
It seems that this error only happens when I rotate along the horizontal axis, but even this case, the error does not happen consistently (e.g. sometimes it works countless times and sometimes it crashes on the second flip).
Upvotes: 1
Views: 672
Reputation: 934
Does your card view need a shadow ? I was able to fix my error by setting elevation of CardView to 0dp. So in xml :-
<android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardElevation="0dp"
app:cardUseCompatPadding="true">
Some other open source projects were also seeing this error :- https://github.com/AnderWeb/discreteSeekBar/issues/73 .
Upvotes: 3