ImageView旋转+填充屏幕

时间:2017-08-10 09:28:25

标签: java android layout rotation

我想用旋转的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解决此问题,或者在不旋转我想要显示的每个图像的情况下以任何其他方式解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可以使用RotateLayout并将您的ImageView放入RotateLayout并以setAngle() RotateLayout方式传递您的轮播,所以它只旋转视图而不是图像,或者我们可以说bitmap它比图像的任何其他旋转速度快得多。

您可以在Gradle文件中添加其依赖项。

用法

在布局文件中添加

<com.github.rongi.rotate_layout.layout.RotateLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:angle="90"> <!-- Specify rotate angle here -->

    <YourLayoutHere
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </YourLayoutHere>
</com.github.rongi.rotate_layout.layout.RotateLayout>

瞧!您的布局将旋转90度。

下载

compile 'rongi.rotate-layout:rotate-layout:3.0.0'

功能

以正确的方式处理所有触摸事件。你按下你触摸的同一个按钮! 布局以正确的方式测量自身。这意味着如果原始视图为50x100,则旋转90度,它将自身测量为100x50,并且可以适合具有此尺寸的另一个布局。

RotateLayout Link