FrameLayout 中的旋转图像未正确旋转

时间:2021-01-19 07:50:12

标签: android imageview android-glide android-framelayout image-rotation

我使用 Glide 来显示图像,我想将它们旋转到不同的角度,

这是我的 xml 代码:

    <FrameLayout
        android:id="@+id/rootImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:layout_gravity="center" />
    </FrameLayout>

这里是java代码:

    public void rotateImage(float rot) {
    if (rot == 90 || rot == 270) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        int height = displayMetrics.heightPixels;
        int width = displayMetrics.widthPixels;
        int offset = (width - height) / 2;
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(height, width);
        ImageLayout.setLayoutParams(lp);
        ImageLayout.setRotation(rot);
        ImageLayout.setTranslationX(offset);
        ImageLayout.setTranslationY(-offset);
    } else {
        ImageLayout.setRotation(rot);
    }
}

当它在 90 时显示这个

this image is having rotation 90 or 270 which shows correct

现在 它有 180 度旋转,图像周围有填充,我怎样才能避免在图像周围填充或调整它的大小而不显示填充,尽管旋转是正确的。

1 个答案:

答案 0 :(得分:0)

使用这个

android:scaleType="fitX"

它将水平扩展您的图像,去除多余的填充

你也可以使用

android:scaleType="fitXY"

它将在垂直和水平方向上扩展

相关问题