use*_*084 8 android bitmap rotation matrix imageview
我正在开发一款游戏,用户需要点击ImageView中的图像来旋转它.在每个拍子图像上顺时针旋转90度.但是图像需要时间从旧位置旋转到新位置.这妨碍了游戏体验.我使用了以下内容:
protected void onCreate(Bundle savedInstanceState)
{
...
...
imgview = (ImageView)findViewById(R.id.imageView1);
imgview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap myImg = getBitmapFromDrawable(imgview.getDrawable());
Bitmap rotated = Bitmap.createBitmap(myImg,0,0,myImg.getWidth(),myImg.getHeight(),matrix,true);
imgview.setImageBitmap(rotated);
}
});
Run Code Online (Sandbox Code Playgroud)
我想知道有没有其他方法旋转图像 而不会产生任何旋转延迟.
elu*_*eci 34
我也试过做一次,找不到任何其他解决方案,但使用动画.我在这里怎么做.
private void rotate(float degree) {
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(0);
rotateAnim.setFillAfter(true);
imgview.startAnimation(rotateAnim);
}
Run Code Online (Sandbox Code Playgroud)
San*_*ojo 15
您不需要旋转对象,旋转视图应该足够了.如果您的目标API> = 11,您可以随时执行此操作.
mImageView.setRotation(angle);
Run Code Online (Sandbox Code Playgroud)
干杯.
| 归档时间: |
|
| 查看次数: |
40602 次 |
| 最近记录: |