首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像移动动画不起作用

图像移动动画不起作用
EN

Stack Overflow用户
提问于 2017-02-15 14:10:16
回答 1查看 181关注 0票数 1

目前,我正在做简单的游戏,如外壳游戏。它在棒棒糖、棉花糖、牛油糖和KitKat 4.4.2上运行良好,但在其他KitKat版本的设备和果冻上不起作用。

移动动画代码是

代码语言:javascript
复制
public class BottomLeftToRightAnimation extends Animation {
private View view;
private float prevX,prevY;
private float cx,cy;
private float prevDx,prevDy;
private float r;
public BottomLeftToRightAnimation(View view,float r){
    this.view = view;
    this.r = r;
}

@Override
public boolean willChangeBounds() {
    return true; // animation will change the view bounds
}

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
    // center position of image
    int cxImage = width/2;
    int cyImage = height/2;
    cx = view.getLeft() + cxImage;
    cy = view.getTop() + cyImage;

    //starting point of image rotation
    prevX = cx+r;
    prevY = cy;
}

// helps to get transformation between the interpolatedTime 0 to 1
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    if (interpolatedTime == 0){
        t.getMatrix().setTranslate(prevDx,prevDy);
        return;
    }
    float angD = (interpolatedTime * -180f) % 180;
    float angR = (float) Math.toRadians(angD);

    float x = (float) (cx + r * Math.cos(angR));
    float y = (float) (cy + r * Math.sin(angR)/1.5);

    float dx = prevX - x;
    float dy = prevY - y;

    prevX = x;
    prevY = y;

    prevDx = dx;
    prevDy = dy;
    t.getMatrix().setTranslate(dx,dy);
}
}

以同样的方式,我为所有的旋转编写代码。我看到很多问题,像problem.The建议使用basket[1].setLayerType(View.LAYER_TYPE_HARDWARE,null);basket[1].setLayerType(View.LAYER_TYPE_SOFTWARE,null);,但它不能修复issue.Please,帮助我修复这个错误。

EN

回答 1

Stack Overflow用户

发布于 2019-11-08 11:40:41

尝试设置背景层的颜色,例如#FFFFFF,以删除动画留下的鬼影图像。

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

https://stackoverflow.com/questions/42241877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档