Reputation: 913
I have an ImageView in my Android project. And i need to rotate this imageview in some cases. All rotations are performed with the help of the rotation animation. But when an ImageView is rotated under 90 or 270 degrees the bitmap inside it is being cropped in top and bottom sides. And i have no idea, why this is happening. Can anyone give me an advice of how to avoid such behaviour?
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);
And this is my ImageView declaration inside xml file:
<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"/>
Upvotes: 1
Views: 266
Reputation: 814
Try changing
RotateAnimation mRotateAnim = new RotateAnimation(oldRotation, newRotation, photoView.getPivotX(), photoView.getPivotY());
with:
RotateAnimation mRotateAnim = new RotateAnimation(oldRotation, newRotation, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
Upvotes: 1