0

I need to prepare FrameLayout (containing ImageView much bigger than screen size and other ImageViews - overlays), which must be simultaneously:

  • rotatable by any angle
  • scrollable both horizontally and vertically

For scrolling I use the solution presented here: https://stackoverflow.com/a/6716638/2274709

My code is as follows:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainView"
    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=".MainActivity">


    <com.chrosciu.konferencja.VScroll android:layout_height="fill_parent"
        android:layout_width="fill_parent" android:id="@+id/vScroll">
        <com.chrosciu.konferencja.HScroll android:id="@+id/hScroll"
            android:layout_width="fill_parent" android:layout_height="fill_parent">

            <FrameLayout
                android:id="@+id/frameLayout"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                >

                <ImageView
                    android:id="@+id/planView"
                    android:src="@drawable/map"
                    android:scaleType="center"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    />

            </FrameLayout>

        </com.chrosciu.konferencja.HScroll>
    </com.chrosciu.konferencja.VScroll>


</RelativeLayout>

MainActivity.java:

  ...

 private void rotate(float angle) {
        FrameLayout frameLayout = (FrameLayout)findViewById(R.id.frameLayout);
        frameLayout.setRotation(angle);
 }

  ....

However this causes some troubles: FrameLayout is cropped after rotation, I cannot reach the corners even by scrolling it manually

Even when I set minHeight and minWidth of FrameLayout to enlarge it after rotation, the result is still not satisfactory:

  • once I enlarge dimensions of FrameLayout I am not able to shrink it back,
  • I have to manually scroll the layout to fit enlarged area

This does not seem to be fanciful task. Am I going the right way? Are there another methods to achieve this?

Community
  • 1
  • 1
chrosciu
  • 304
  • 3
  • 9

1 Answers1

0

Finally I managed to implement something usable. This is still not 100% what I expected, but enough for my purposes. Thanks @pskink for directing...

The solution is as follows:

  • Calculate diagonal size of the ImageView (we assume that ImageView is rectangular)
  • Set minHeight and minWidth of FrameLayout to be equal to this diagonal (rounding up to nearest integer)
  • Move the ImageView (via setX() and setY()) to the center of FrameLayout

With these assumptions after rotating ImageView by any angle it will always be inside FrameLayout and will never be cropped.

chrosciu
  • 304
  • 3
  • 9