ImageView rotate + fill screen

Viewed 1246

I would like to fill the screen with a rotated ImageView. The question of how to fill the screen with an ImageView and how to rotate an ImageView has been answered seperately mutlipe times on the site. My XML code looks as follows.

<ImageView
  android:id="@+id/video_frame"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:adjustViewBounds="true"
  android:scaleType="fitCenter"
  android:rotation="270"
/>

The problem is that the rotation happens after the image has been fitted with no rotation applied and I end up with an image that does not fill the screen.

I could of course just rotate the images (and remove the ImageView rotation) as follows:

 Matrix mMatrix = new Matrix();
 mMatrix.postRotate(-90);
 ImageView video = (ImageView)findViewById(R.id.video_frame);
 Bitmap frame = BitmapFactory.decodeFile("path/to/file.jpg");
 Bitmap frame2 = Bitmap.createBitmap(frame, 0, 0, frame.getWidth(), frame.getHeight(), mMatrix, true);
 video.setImageBitmap(frame2);

Here the problem is that the application is realtime and I am serving multipe frames per second (20+). The rotation per frame seems to be quite heavy and even if in this case the images fill the screen, the result is lagging and not as responsive as without the matrix rotation.

My question would therefore be if I could solve this issue with XML only or in any other way without rotating every image I want to display?

1 Answers
Related