我希望用旋转的ImageView填满屏幕。如何用ImageView填满屏幕以及如何旋转ImageView的问题已经在该网站上独立回答了多次。我的XML代码如下。
<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"
/>
问题在于,旋转发生在图像被适配且未应用旋转之后,因此我得到的图像不会填充整个屏幕。
当然,我可以按照以下方式旋转图像(并删除 ImageView 旋转):
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);
问题在于这个应用是实时的,我每秒要提供多个帧(20+)。每帧的旋转似乎相当耗费性能,即使在这种情况下图像填满屏幕,结果也会出现延迟,并且不如没有矩阵旋转时那么响应。
因此,我的问题是是否可以仅通过XML或其他方式解决此问题,而无需对要显示的每个图像进行旋转?
RotateLayout
的layout_height="fill_parent"
(在90度旋转后变为宽度)。 - rex123