Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 图像移动动画不工作_Android_Android Animation - Fatal编程技术网

Android 图像移动动画不工作

Android 图像移动动画不工作,android,android-animation,Android,Android Animation,目前我正在做一些简单的游戏,比如shell游戏。它在棒棒糖、棉花糖、牛轧糖和KitKat 4.4.2中运行良好,但在其他KitKat版本设备和Jellybean中不起作用 移动动画代码是 public class BottomLeftToRightAnimation extends Animation { private View view; private float prevX,prevY; private float cx,cy; private float prevDx,prevDy;

目前我正在做一些简单的游戏,比如shell游戏。它在棒棒糖、棉花糖、牛轧糖和KitKat 4.4.2中运行良好,但在其他KitKat版本设备和Jellybean中不起作用

移动动画代码是

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);
}
}

我用同样的方法为所有旋转编写代码。我看到了许多类似于相同问题的问题。建议使用
basket[1]。setLayerType(View.LAYER\u TYPE\u HARDWARE,null)
篮子[1]。setLayerType(视图。图层类型软件,空)但它无法修复问题。请帮助我修复此错误

尝试使用颜色(例如#FFFFFF)设置背景层,以删除动画留下的重影图像

尝试使用颜色(例如#FFFFFF)设置背景层,以删除动画留下的重影图像

你想要实现什么,在你前进的道路上有什么问题?我希望我的形象必须无故障地前进。你想要实现什么,在你前进的道路上有什么问题?我希望我的形象必须无故障地前进。