Ich versuche, Oval Pfadanimation zu implementieren, ich möchte Pfadanimation mit Bild zeigen, versuchte ich https://github.com/matthewrkula/AnimatedPathView, aber es ist nicht funktionieren für Oval. Ich habe auch unten Code für ovalen Pfad versucht, aber es ist zeigt Kreis, hat jemand eine Idee? Danke im Voraus!!!Oval Pfad Animation mit Bild
MyAnimation.java
public class MyAnimation extends Animation {
private View view;
private float cx, cy; // center x,y position of circular path
private float prevX, prevY; // previous x,y position of image during animation
private float r; // radius of circle
private float prevDx, prevDy;
/**
* @param view - View that will be animated
* @param r - radius of circular path
*/
public MyAnimation(View view, float r){
this.view = view;
this.r = r;
}
@Override
public boolean willChangeBounds() {
return true;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
// calculate position of image center
int cxImage = width/2;
int cyImage = height/1;
cx = view.getLeft() + cxImage;
cy = view.getTop() + cyImage;
// set previous position to center
prevX = cx;
prevY = cy;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if(interpolatedTime == 0){
t.getMatrix().setTranslate(prevDx, prevDy);
return;
}
float angleDeg = (interpolatedTime * 360f + 90) % 360;
float angleRad = (float) Math.toRadians(angleDeg);
// r = radius, cx and cy = center point, a = angle (radians)
float x = (float) (cx + r * Math.cos(angleRad));
float y = (float) (cy + r * Math.sin(angleRad));
float dx = prevX - x;
float dy = prevY - y;
prevX = x;
prevY = y;
prevDx = dx;
prevDy = dy;
t.getMatrix().setTranslate(dx, dy);
}
}
PathAnimation.java
image = (ImageView) findViewById(R.id.image);
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation anim = new MyAnimation(image, 300);
anim.setDuration(1000);
image.startAnimation(anim);
}
});
Bitte guyz helfen, dieses Problem zu lösen !!! –