Как я могу включить растровое изображение, которое не все на экране - PullRequest
2 голосов
/ 25 ноября 2011

Я пытаюсь повернуть изображение, частично помещенное на экран, с помощью этого кода:

    final float ROTATE_FROM = 0.0f;
    final float ROTATE_TO = 360.0f;
    RotateAnimation r = new RotateAnimation(ROTATE_FROM, ROTATE_TO,
            Animation.RELATIVE_TO_SELF, 0f,
            Animation.RELATIVE_TO_SELF, 0f);
    r.setDuration(300000);     
    r.setRepeatCount(Animation.INFINITE);
    r.setInterpolator(this, android.R.anim.linear_interpolator);

    imv = (ImageView) findViewById(R.id.imageView1);

    imv.startAnimation(r);

Но то, что я получаю, - это вращение изображения, и его части остаются вне экрана.

Что нужно, чтобы результат был:

Демон http://www.11sheep.com/temp/p1.png

Может кто-нибудь дать мне фрагмент кода?

1 Ответ

1 голос
/ 01 декабря 2011

вот код

            Animation anim =new FlipAnim(0, 90, card.getWidth()/2, card.getHeight()/2);
            anim.setAnimationListener(new Animation.AnimationListener() {
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub
        }
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub
        }
        public void onAnimationEnd(Animation animation) {


            //              

            Animation anim2 =new FlipAnim(-90, 0, card.getWidth()/2, card.getHeight()/2);
            card.startAnimation(anim2);
        }
    });
    card.startAnimation(anim);

вот код для FlipAnim

      import android.graphics.Camera;
      import android.graphics.Matrix;
      import android.view.animation.Animation;
      import android.view.animation.Transformation;

  public class FlipAnim  extends Animation {
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private Camera mCamera;

public FlipAnim(float fromDegrees, float toDegrees,
        float centerX, float centerY) {
    mFromDegrees = fromDegrees;
    mToDegrees = toDegrees;
    mCenterX = centerX;
    mCenterY = centerY;
    setDuration(400);
}

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
    mCamera = new Camera();
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();

    camera.rotateY(degrees);


    camera.getMatrix(matrix);
    camera.restore();
    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);

}
...