android中心点旋转晃动_Android:如何在中心点上旋转位图

我一直在寻找解决此问题的解决方案,但是没有任何帮助,甚至是这里的答案。文档也没有解释任何内容。

我只是试图使旋转方向朝另一个对象的方向。问题在于位图不是围绕固定点旋转,而是围绕位图(0,0)旋转。

这是我遇到麻烦的代码:

Matrix mtx = new Matrix();

mtx.reset();

mtx.preTranslate(-centerX, -centerY);

mtx.setRotate((float)direction, -centerX, -centerY);

mtx.postTranslate(pivotX, pivotY);

Bitmap rotatedBMP = Bitmap.createBitmap(bitmap, 0, 0, spriteWidth, spriteHeight, mtx, true);

this.bitmap = rotatedBMP;

奇怪的是,无论如何更改pre/中的值postTranslate()以及中的float参数,都没有关系setRotation()。有人可以帮忙,把我推向正确的方向吗?:)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android中,可以使用属性动画来实现抖动动画吸引用户的注意力。以下是一个简单的示例代码: ```java // 获取需要抖动的视图 View view = findViewById(R.id.my_view); // 定义抖动动画 ObjectAnimator animator = ObjectAnimator.ofFloat(view, "rotation", -5, 5); animator.setDuration(100); animator.setRepeatCount(5); animator.setRepeatMode(ObjectAnimator.REVERSE); // 开始动画 animator.start(); ``` 这个代码会使得视图向左旋转5度,然后向右旋转5度,重复执行5次,每次执行时间为100毫秒。通过这个抖动动画,可以吸引用户的注意力。 如果想要实现中心点旋转的效果,可以在抖动动画的基础上加入平移动画,使得视图围绕中心点旋转。以下是一个修改后的示例代码: ```java // 获取需要旋转的视图 View view = findViewById(R.id.my_view); // 获取视图的中心点坐标 int cx = view.getWidth() / 2; int cy = view.getHeight() / 2; // 定义旋转动画 ObjectAnimator rotation = ObjectAnimator.ofFloat(view, "rotation", 0, 360); rotation.setDuration(2000); rotation.setInterpolator(new LinearInterpolator()); rotation.setRepeatCount(ObjectAnimator.INFINITE); // 定义平移动画 ObjectAnimator translationX = ObjectAnimator.ofFloat(view, "translationX", 0, cx); translationX.setDuration(1000); translationX.setRepeatCount(1); translationX.setRepeatMode(ObjectAnimator.REVERSE); // 合并动画 AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(rotation, translationX); // 开始动画 animatorSet.start(); ``` 这个代码会使得视图围绕中心点旋转,并且在动画过程中会进行一次平移,使得视图的中心点旋转过程中保持不变。通过这个中心点旋转的效果,可以吸引用户的注意力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值