改变方向时不要改变背景
在我的应用程序中,我有一个图像作为背景。当应用程序处于纵向模式时,这很好。但当处于横向模式时,图像会旋转并被拉伸。
我知道我们可以使用layout-land文件夹,但是使用这个解决方案,我的所有布局都将是双精度的,仅用于图像(不太合乎逻辑......)。
还有其他解决方案吗?
PS:我的图像只是碳纹理,因此,防止其随方向转动的解决方案就可以了。
编辑:
hotveryspicy,您的解决方案有效,但是,有些活动具有属性 android:configChanges="orientation" (在清单中),并且它对它们不起作用。怎么解决这个问题呢?
事实上,我使用此属性在方向更改时保存状态,但这不是这样做的好方法。我需要为此使用 onSaveInstanceState 。
与此同时,是否有一个解决方案可以让我保留这个糟糕的解决方案?
In my application, I have an image as background. When the application is in portrait mode, that's fine. But when it is in landscape mode, the image turns and is stretched.
I know that we can use the layout-land folder, but with this solution, all my layouts will be in double just for an image (not very logical..).
Is there another solution?
PS : My image is just a carbon texture so, a solution to prevent it to turn with orientation would be ok.
EDIT :
hotveryspicy, your solution works BUT, there are activities which have the property android:configChanges="orientation" (in the Manifest), and it doesn't work for them. How to solve this?
In fact, I use this property to save state when the orientation changes but it's not the good way to do that. I need to use onSaveInstanceState for that.
In the meantime, is there a solution which allows me to keep this bad solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,首先检查 onCreate() 中的方向
ya, first check orientation in onCreate()
如果将背景图像的替代版本放入
drawable-land
res 文件夹中,是否可以解决问题?这样您仍然可以使用相同的布局文件并引用其中的@drawable/background
。Would it do the trick if you placed alternate version of the background image into
drawable-land
res folder? This way you can still use the same layout files and refer to the@drawable/background
in them.我怀疑是否可以做你所描述的事情。您已经排除了唯一可能的解决方案(布局土地)。我想这是唯一的方法。
I doubt it would be possible to do what you had described. The only solution which was possible (layout-land) you had already ruled out. It is the only way to go about it I guess.