Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中旋转背景图像_Android_Image Rotation_Autorotate - Fatal编程技术网

如何在android中旋转背景图像

如何在android中旋转背景图像,android,image-rotation,autorotate,Android,Image Rotation,Autorotate,我有用于纵向定位的背景图像。但,当我改变手机的旋转(横向),应用程序改变图像的比例。我希望应用程序将其旋转。您可以使用此代码旋转图像 private static Bitmap rotateImage(Bitmap source, float angle) { Matrix matrix = new Matrix(); matrix.postRotate(angle); return Bitmap.createBitmap(source, 0, 0, source.g

我有用于纵向定位的背景图像。但,当我改变手机的旋转(横向),应用程序改变图像的比例。我希望应用程序将其旋转。

您可以使用此代码旋转图像

  private static Bitmap rotateImage(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
            matrix, true);
}

使用所需的任何编辑器手动旋转图像,并将其放置在drawable land文件夹中

这样,当手机旋转到横向时,系统将拾取您放置在该文件夹中的资源(图像),而不是默认可绘制文件夹中使用的“纵向”资源

这个扩展可以与任何其他扩展一起工作,因此您可以使用可绘制的xhdpi扩展

屏幕定向端口 土地
端口:设备处于纵向(垂直) 接地:设备处于横向(水平) 如果用户旋转屏幕,在应用程序的生命周期内,这可能会发生变化。有关在运行时如何影响应用程序的信息,请参阅处理运行时更改。另请参见方向配置字段,该字段指示当前设备方向


请参见

您的意思是,您想单独旋转应用程序UI(而不旋转背景图像)?@Sackurise否,我也想旋转BG图像。但是它改变了比例,而不是旋转为什么这是用Kotlin标记的?这在Java和Kotlin中都没有代码。