【问题标题】:Rotating Image in FrameLayout is not rotating correctlyFrameLayout 中的旋转图像未正确旋转
【发布时间】:2021-01-19 07:50:12
【问题描述】:

我正在使用 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 时显示这个

现在 它有 180 度旋转并且图像周围有填充我如何避免在图像周围填充或调整它的大小而不显示填充虽然旋转是正确的。

【问题讨论】:

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


    【解决方案1】:

    使用这个

    android:scaleType="fitX"
    

    它将横向扩展您的图像,去除多余的填充

    你也可以使用

    android:scaleType="fitXY"
    

    它会在垂直和水平方向扩展

    【讨论】:

    • 但这会覆盖实际图像大小。我想以实际大小旋转图像。
    猜你喜欢
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    相关资源
    最近更新 更多