Вот как близко я мог бы достичь с помощью комбинации моего ответа rotation of image around itself и this post of moving image in a circular path
//i is my ImageView here
// method to rotate globe
private void applyRotation(float start, float end) {
//first animation for circular path
final Animation rotation = new MyAnimation(i, 2000);
rotation.setDuration(10000);
rotation.setRepeatCount(0);
//rotation of iamge
final Animation rotation2 = new RotateAnimation(30, 360, i.getWidth()/2, i.getHeight()/2);
rotation2.setFillAfter(true);
rotation2.setRepeatCount(0);
rotation2.setDuration(10000);
rotation2.setInterpolator(new LinearInterpolator());
//combine in a Set
AnimationSet s = new AnimationSet(false);
s.addAnimation(rotation);
s.addAnimation(rotation2);
i.startAnimation(s);
}
MyAnimation.java
package com.example.tempp;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
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
/**
* @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/2;
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){
// I ran into some issue where interpolated would be
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;
t.getMatrix().setTranslate(dx, dy);
}
}
Надеется, что это помогает.
Вы имеете в виду что-то вроде [this] (http://stackoverflow.com/q/25718765/1777090)? –
не так ... проверьте изображение выше и он должен вращаться по часовой стрелке, как земной шар будет вращаться в 3d. MysticMagic говорит, как вращаться в 3d. заранее спасибо –
Используя ваш код, он перемещается, оставляя свое место. Вы хотите оживить изображение в одном и том же месте? или хотите, чтобы его положение изменилось круговым движением? –