目前我正在进行像shell游戏一样的简单游戏。它在Lollipop,Marshmallow,Nougat和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_TYPE_HARDWARE,null);
或basket[1].setLayerType(View.LAYER_TYPE_SOFTWARE,null);
,但它不能解决问题。请帮我解决这个问题。
答案 0 :(得分:0)
尝试将背景图层设置为一种颜色,例如#FFFFFF删除动画留下的重影。