gpt4 book ai didi

java - ImageView旋转+填屏

转载 作者:行者123 更新时间:2023-11-30 10:26:38 25 4
gpt4 key购买 nike

我想用旋转的 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并将您的 ImageView 放入 RotateLayout并在 setAngle() 中传递你的轮换RotateLayout的方法| , 所以它只旋转 View 而不是图像或者我们可以说 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'

特点

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

RotateLayout Link

关于java - ImageView旋转+填屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45609665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com