Android:将ImageView中的图像旋转90度但没有延迟

Android: Rotate image in ImageView by 90degrees but without delay(Android:将ImageView中的图像旋转90度但没有延迟)
本文介绍了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度但没有延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)