I have background image for portrait orientation. But when I change phone's rotation(to landscape), app changes scale of image. I want app to rotate it instead.
-
You mean, you want to rotate the app UI alone(without rotating background image)? – Sackurise Oct 30 '17 at 13:53
-
@Sackurise No, I want to rotate BG image too. But it changes scale, instead of rotating – Бауыржан Нургалиев Oct 30 '17 at 13:54
-
Why is this tagged with Kotlin? This has zero code both in Java and Kotlin. – M. Prokhorov Oct 30 '17 at 14:00
2 Answers
You can use this code to rotate your image
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);
}

- 437
- 4
- 10
Rotate your image manually using whatever editor you want, and place it in the drawable-land folder.
This way, when the phone is rotated to landscape, the system will pick up the resource (image) that you placed in that folder instead of the "portrait" one used in the default drawable folder.
This -land extension works with any other, so you can have drawable-xhdpi-land.
Screen orientation port land
port: Device is in portrait orientation (vertical) land: Device is in landscape orientation (horizontal) This can change during the life of your application if the user rotates the screen. See Handling Runtime Changes for information about how this affects your application during runtime. Also see the orientation configuration field, which indicates the current device orientation.
See https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

- 5,212
- 2
- 22
- 36