简体   繁体   中英

Android auto-rotate dialogs but not background image

I am working on a home automation app where users will have the capability to upload images (such as floor plans), tap on a room and do different things such as control lighting, etc. I figure out where the user has tapped by using a second image that the user also creates with a color map. I have it set up right now so that the images have to be the same resolution as the device so I don't have to deal with scaling. I also disable auto-rotation so they don't have to worry about a landscape photo being scrunched up when the device is rotated to portrait orientation. In other words, I was too lazy to deal with it. The problem with this approach is that any dialogs that come up (while viewing the screen in landscape), come up in portrait mode rather than landscape. So my question is, is there a way for me to have an image on the screen that does not obey the auto-rotation, but have dialogs follow the auto-rotation? Or is the right solution for me to deal with the auto-rotation for the images too? I suppose one thing I could do is fix the rotation to landscape mode, since most of the floorplan drawings will lend themselves to landscape orientation, but what if someone does want a portrait image?

In my (not so) humble opinion, you should not be fixing the orientation without very good reason and forgive me, but "I'm lazy" is not a good reason ;)

There are several options available to you.

Without doing anything, setting the scaleType property of an Imageview will enable you to load an image, scaled with the ratio intact. You could then override the onConfgurationChanged callback and set the scaleType to one that makes sense for your app, depending on the image orientation (just check width>height).

Or, you could measure the ratio of the app and then set the orientation to portrait or landscape whilst viewing the image then switch to the current device orientation when the user closes the image viewing activity.

Your users will be happier and you will end up with more elegant, more supportable and more satisfying code.

My experience tells me that not taking the time to do this kind of stuff right up-front ultimately results in more work and/or pain.

Do yourself a favour (and your users) and do it right...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM