简体   繁体   English

Android自动旋转对话框,但不自动旋转背景图片

[英]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. 无需执行任何操作,设置Imageview的scaleType属性将使您可以加载完整比例的图像。 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). 然后,您可以覆盖onConfgurationChanged回调,并将scaleType设置为对您的应用有意义的一个,具体取决于图像的方向(只需检查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... 帮自己(和您的用户)一个忙,然后正确地做...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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