Android:将ImageView中的图像旋转90度但没有延迟 [英] Android: Rotate image in ImageView by 90degrees but without delay

查看:28
本文介绍了Android:将ImageView中的图像旋转90度但没有延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个游戏,用户需要点击 ImageView 中的图像来旋转它.在每个点击图像顺时针方向旋转 90 度.但是图像从旧位置旋转到新位置需要时间.这阻碍了游戏体验.我使用了以下内容:

I am developing a game where a user needs to tap on the image in ImageView to rotate it. On each tap image rotates by 90 degrees in clockwise direction. But image is taking time to rotate from old to new position. This is hampering the gameplay experience. I have used the following:

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

我想知道是否有任何其他旋转方式图像不会造成任何延迟.

I want to know is there any other way to rotate the image without creating any delay in rotation.

推荐答案

我也尝试过一次,除了使用动画找不到任何其他解决方案.我会怎么做.

I also tried to do it once and couldn't find any other solution but using animation. Here how I'd do.

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

这篇关于Android:将ImageView中的图像旋转90度但没有延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆