首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >摄像头动画中的Android OpenGL错误

摄像头动画中的Android OpenGL错误
EN

Stack Overflow用户
提问于 2016-03-20 07:50:06
回答 1查看 651关注 0票数 0

我找到了以下代码,用于翻转包含图表的两个CardViews (我使用MPAndroidCharts库),从而创建了3D卡翻转效果:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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);
}

原始代码只能沿垂直中心轴翻转,所以我在设置布尔值时添加了小if,然后沿水平中心轴制作动画。现在,有时在动画过程中,以下奇怪的错误会使我的应用程序崩溃:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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)

这个错误似乎只发生在沿水平轴旋转时,但即使在这种情况下,错误也不会持续发生(例如,它有时工作无数次,有时在第二次翻转时崩溃)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-16 00:02:37

你的卡视图需要阴影吗?我能够通过将CardView的高度设置为0dp来修复我的错误。所以在xml中:-

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<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">

其他一些开源项目也看到了这个错误:- https://github.com/AnderWeb/discreteSeekBar/issues/73

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36115934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文