Image moving animation is not working

2019-05-31 03:31发布

问题:

Currently i'm doing simple game like shell game. It's working good in Lollipop,Marshmallow,Nougat and KitKat 4.4.2 but not working in other KitKat version device and Jellybean.

Moving animation code is

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

This same way i wrote code for all rotation. I saw many question like same problem.The suggested to use basket[1].setLayerType(View.LAYER_TYPE_HARDWARE,null); or basket[1].setLayerType(View.LAYER_TYPE_SOFTWARE,null); but it doesn't fix the issue.Please help me to fix this bug.