0

I'm rotating a zoom-able ImageView upon button click as follows:

Float cur_angle = imageView.getRotation();
            imageView.setPivotX(imageView.getWidth() / 2);
            imageView.setPivotY(imageView.getHeight() / 2);
            imageView.animate().rotation(cur_angle + add_angle).setDuration(delay);
            imageView.invalidate();

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivityFragment"
android:id="@+id/rel_layout" >


<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/map_view"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/store_map"
    android:scaleType="centerCrop"
    android:layout_alignParentBottom="false" />


<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Rotate"
    android:id="@+id/rotate_right"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

After a 90 degree rotation (add_angle = 90), in case I zoom-in so the image is large enough in the Y axis, the image gets cut at the top and bottom. It seems like the imageView vertical dimension is kept equal or smaller than the original imageView width, which was limited to the width of the RelativeLayout it resides in (which is limited to the display size).

Why doesn't it "match parent" automatically after rotation and how do I force it to?

Just for the sake of experiemnt I've tried rotation without animation but it makes no difference.

Thanks

Yaron
  • 11
  • 4

1 Answers1

0

Well, look at your method. It takes your actual height and weight at specific state, so if you simply change your orientation, it would recreate your imageview but with these 'saved' parameters, that's why your imageView looks bad after changing orientation

You need to use 'onOrientationChangeMethod' to redefine your imageview parameters.

Read patiently this guide: http://developer.android.com/guide/topics/resources/runtime-changes.html

and then: How to detect orientation change in layout in Android?

Hope it help

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • Thanks for the answer but I'm not sure I get what you mean. Note that the ImageView is rotated (I should have mentioned, 90 deg rotation) when a button is clicked and not upon phone orientation change so I believe "onOrientationChange" is not relevant here?. Further more, the width and the height are used only to define the pivot point. – Yaron Dec 18 '15 at 09:30
  • is your imageview or its parent have `wrap_parent` at `layout_height`? maybe you should change to match_parent? Also add a screenshot, to give me some light to understand this project – piotrek1543 Dec 18 '15 at 10:24
  • Edited the question so I hope it's clearer now. I would have added screenshots but I'm new here and my low reputation doesn't allow that :) Did you mean `match parent`? If so, the answer is I tried it too. No change. – Yaron Dec 18 '15 at 14:31