gpt4 book ai didi

android - 我怎样才能把一个不在屏幕上的位图

转载 作者:行者123 更新时间:2023-11-29 02:09:33 24 4
gpt4 key购买 nike

我正在尝试使用以下代码旋转部分放置在屏幕上的图像:

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

但我得到的是旋转的图像,屏幕外的部分是空白的。

想要的结果是:

a demopic http://www.11sheep.com/temp/p1.png

有人可以给我一个代码 fragment 吗?

最佳答案

这是代码

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

代码如下翻转动画

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

}

关于android - 我怎样才能把一个不在屏幕上的位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8270893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com