android - ImageView 中的位图在旋转后被裁剪

标签 android bitmap rotation

我的 Android 项目中有一个 ImageView。在某些情况下我需要旋转这个 ImageView 。所有旋转都是在旋转动画的帮助下执行的。但是,当 ImageView 旋转 90 度或 270 度时,其中的位图会在顶部和底部被裁剪。我不知道为什么会这样。谁能给我建议如何避免这种行为?

            final ImageView photoView = (ImageView)  main_activity.findViewById(R.id.photo_view);
            RotateAnimation mRotateAnim = new RotateAnimation(oldRotation, newRotation, photoView.getPivotX(), photoView.getPivotY());
            mRotateAnim.setDuration(500);
            mRotateAnim.setFillAfter(true);
            photoView.startAnimation(mRotateAnim);

这是我在 xml 文件中的 ImageView 声明:

<ImageView
           android:id="@+id/photo_view"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_centerInParent="true"
           android:layout_above="@+id/bottom_container"
           android:adjustViewBounds="true"/>

最佳答案

尝试改变

RotateAnimation mRotateAnim = new RotateAnimation(oldRotation, newRotation, photoView.getPivotX(), photoView.getPivotY());

与:

RotateAnimation mRotateAnim = new RotateAnimation(oldRotation, newRotation, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

关于android - ImageView 中的位图在旋转后被裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38127679/

相关文章:

iphone - 带旋转的drawAtPoint

c++ - 仿射变换、简单旋转和缩放或其他完全?

Android:Shape "corners"问题。这是一个错误吗?

android - URL 连接关闭有时会挂起

android - 位图大小大于宽度和高度

java - 在 Android 应用程序中将位图图像转换/保存为文件

Android,应用程序在屏幕旋转时崩溃并打开对话框

android - 如何使用 LinearLayout 定位 Button 死点

android - 在android中通过ffmpeg合并两个mp3文件不起作用

android - 我在 ImageView 类型中得到 setImageBitmap(Bitmap) 不适用于参数 (byte[])